"In a PUT request, the enclosed entity is considered to be a modified version of the resource stored on the origin server, and the client is requesting that the stored version be replaced. With PATCH, however, the enclosed entity contains a set of instructions describing how a resource currently residing on the origin server should be modified to produce a new version."
HTTP Patch Method is used to update the JSON Resource efficiently.
JSON Patch
JSON Example :
{
"name": "abc123",
"colour": "blue",
"count": 4
}
and you want to update the “count” member’s value to “5”.
Now, you could just PUT the entire thing back with the updated value, but that requires a recent GET of its state, can get heavyweight (especially for mobile clients),
For these and other reasons, many APIs define a convention for POSTing to resources that allows partial updates. E.g.
POST /widgets/abc123?action=incrementCount
PATCH /widgets/abc123 HTTP/1.1
Host: api.example.com
Content-Length: ...
Content-Type: application/json-patch
[
{"replace": "/count", "value": 5}
]
Easy to understand, and even write by hand. If it succeeds, the response can be as simple as:
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Your patch succeeded. Yay!
No comments:
Post a Comment