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; }
}
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"
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.