Let me give an example which troubles me when using JSON-Patch message in PATCH message in a RESTFul API.
If we have a structure like:
{"books": [
{"title": "HTTP-Protocol", "image": "http.jpg", "description": "A standard book on HTTP", "status": "Available"},
{"title": "JSON-Patch", "image": "patching.jpg", "description": "Explanation on how to use json-patch in RESTFul", "status": "Planned"},
{"title": "RESTFul", "image": "fielding.jpg", "description": "Representational state transfer", "status": "Available"}
]}
Now the client who requested this information wants to change the status of the third book (RESTFul) from "Available" to "Borrowed".
Using JSON-Patch he would send the following message:
[
{
"op": "replace",
"path": "/books/2/status",
"value": "Borrowed"
}
]
Meaning that from the list, as he saw it, he wants to change the status of the third item. But since a RESTFul API call is stateless the server does not know anymore what list it gave to the client. Maybe in the mean time a new book was added and the list on the server change to:
{"books": [
{"title": "HTTP-Protocol", "image": "http.jpg", "description": "A standard book on HTTP", "status": "Available"},
{"title": "In between", "image": "destroy.jpg", "description": "Not RESTFul?", "status": "Available"},
{"title": "JSON-Patch", "image": "patching.jpg", "description": "Explanation on how to use json-patch in RESTFul", "status": "Planned"},
{"title": "RESTFul", "image": "fielding.jpg", "description": "Representational state transfer", "status": "Available"}
]}
Then this json-patch message received from the client will change the book with the title "JSON-Patch" and not the book with title "RESTFul" as intended by the client.
What is in your opinion the solution for this problem?