1

I need to implement a way to increase view count for my posts when the post is viewed on the client side. For now, I won't be handling removing duplicate views by refreshing.

If PATCH or PUT is sent to the server with the viewcount + 1 on client side, viewcount will be overridden if multiple users use my service.

Is creating a new endpoint only for increasing the view count the best practice? If so, what would be the correct URI staying RESTful? (POST /post/count ?)

J.S.C
  • 1,323
  • 3
  • 16
  • 22
  • You can save `F('count')+1` to the database, then it is incremented in a transaction, so if the transaction can be atomically processed, it is incremented. – Willem Van Onsem May 07 '20 at 15:41

1 Answers1

0

Multiuser

Your endpoint should increment the viewcount in a transaction.

https://docs.djangoproject.com/en/3.0/topics/db/transactions/

This solves the issue of multiple Users using the page.

Restful

according to this answer and after looking into this

I would say a patch request

bb4L
  • 899
  • 5
  • 16