DEV Community

Discussion on: How to show recently viewed items in REST API?

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.