If the web API allows to increment a model objects's counter, it should have a dedicated "method" for that.
Generally, an Increment Counter feature won't work reliable if the client itself increments the counter performed on a local copy which it received before from the server and then tries to update the server's value via composing a PATCH request where the client sends just the value local_counter+1
. In the meantime, other clients could have the same idea, in which case the counter value on the server would be become corrupt. Also, one could update the counter on the server to any value - which is certainly not desired.
This has the consequence, that the counter variable MUST be read only for the clients.
There must be other means (defined by the web API) where a client can accomplish this. For example, a REST API would define a particular "resource" (e.g. some sort of "ticket" or "reservation") which a client can create. The creation of this resource will have the effect of incrementing the counter variable on the server.
Edit
If you are testing a web API, the command line tool curl
is invaluable:
Test the PATCH request:
In Terminal.app enter this command:
curl -sSv -X PATCH \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"email”:”jappleseed@mail.com"}' \
http://localhost:3000/api/v1/users/123 \
| python -m json.tool