Incrementing resource counter in a RESTful way: PUT vs POST

后端 未结 4 1413
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 18:15

I have a resource that has a counter. For the sake of example, let\'s call the resource profile, and the counter is the number of views

4条回答
  •  渐次进展
    2021-01-31 18:31

    After evaluating the previous answers I decided PATCH was inappropriate and, for my purposes, fiddling around with Content-Type for a trivial task was a violation of the KISS principle. I only needed to increment n+1 so I just did this:

    PUT /profiles/123$views
    ++
    

    Where ++ is the message body and is interpreted by the controller as an instruction to increment the resource by one.

    I chose $ to deliminate the field/property of the resource as it is a legal sub-delimiter and, for my purposes, seemed more intuitive than / which, in my opinion, has the vibe of traversability.

提交回复
热议问题