How to control GET method in API

I am developing an API by looking at the documentation on HTTP methods, which says that "GET" should not change the state of a resource. What if I want to calculate how many times a resource is viewed and return it in response?

Sort of

GET /resource/1
{
   "content": "This is the resource 1",
   "view_count": 1
}

In the next call, it returns:

GET /resource/1
{
   "content": "This is the resource 1",
   "view_count": 2
}

Am I breaking a rule?

+4
source share
2 answers

, , view_count GET, , , view_count . . , . - GET /resource/1?include=view_count. , .

+2

GET, , . , .

Edit:

- ( ), API PATCH GET, view_count.

, , , view_count , API, .

, - Google Analytics , -...

0

Source: https://habr.com/ru/post/1625373/


All Articles