DEV Community

Bhumanyu Kumar
Bhumanyu Kumar

Posted on

How to show recently viewed items in REST API?

I am using Nodejs, Express, Mongodb. There is no session management on the server side. (1. Android app, 1. IOS app and 1. Web application is consuming this api). I have no idea how can i implement the "Recently viewed" products/items.

Top comments (4)

Collapse
 
leandroandrade profile image
Leandro Andrade

Hi. Do you tried to check the client request headers? I believe you can get useful informations.

Collapse
 
bhumanyukumar profile image
Bhumanyu Kumar

Hi. Thanks for the response. Actually, i couldn't understand what you're trying to say about headers. I use header for auth token only. That too in case, if user is registered user. How can i use headers for showing recently viewed products/items(for registered as well as non registered user). Can you please elaborate what you are trying to say?

Collapse
 
leandroandrade profile image
Leandro Andrade

Hi. I am try to say this: imagine that clients consume your API, like a specific path. I think that you can get a lot information about your clients in request headers, like ip address, auth token, system operational, browser, request time and so fourth.

I am not clear if this you need, but a think that can help you.

Thread Thread
 
bhumanyukumar profile image
Bhumanyu Kumar

If i managed to get the ip address, still i won't be able to track the recently visited products/items. Cuz the data related to product is served in the first request when the list of products is fetched on the frontend(A SPA using angular). Then the same information is shown on product detail page(No new request is made on the product detail page). So how can i track that how many times a product is viewed. Also one more point i want to mention here that i am not in favor of making entries in database for each product with its view counts. Cuz it will be very inefficient as database writes per request could lead to database I/O bottleneck. Since there is no session managed, its more complicated to track user activity in session.