Reputation: 45095
I am new to PATCH|MERGE and want to know how to use it, client-side. I am not sure what to send in the body of the payload in JSON.
Here is a contrived example POCO model in C# for discussion purposes.
public class Person
{
public Guid Id { get; set; }
public string FullName { get; set; }
public int Age { get; set; }
}
Upvotes: 2
Views: 1480
Reputation: 45095
If you Google for an answer, you'll see various examples of JSON patch where the JSON payload describes one or more operations, such as this one which replaces/updates a value:
PATCH /people/guid123lalala HTTP/1.1
Content-Type: application/json-patch
{
"op": "replace",
"path": "/FullName",
"value": "Willy Lopez"
}
Or this one:
PATCH /people/guid123lalala HTTP/1.1
Content-Type: application/json-patch
[
{"replace": "/FullName", "value": "Willy Lopez"}
]
(Which I'm not even sure is correct for JSON-patch.)
However, the application/json-patch
format is not supported. So as of January 2015, for OData on WebApi 2.2, just send the object with the non-changing properties omitted, like this using normal JSON:
PATCH /people/guid123lalala HTTP/1.1
Content-Type: application/json
{
FullName: "Willy Lopez"
}
Upvotes: 3