3. 示例 (Example)
3. 示例 (Example)
给定以下示例 JSON document:
{
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
}
如果 user agent 希望将 "title" member 的值从 "Goodbye!" 改为 "Hello!", 添加新的 "phoneNumber" member, 从 "author" object 中移除 "familyName" member, 并替换 "tags" array 使其不包含单词 "sample", 则会发送以下请求:
PATCH /my/resource HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json
{
"title": "Hello!",
"phoneNumber": "+01-123-456-7890",
"author": {
"familyName": null
},
"tags": [ "example" ]
}
生成的 JSON document 将是:
{
"title": "Hello!",
"author" : {
"givenName" : "John"
},
"tags": [ "example" ],
"content": "This will be unchanged",
"phoneNumber": "+01-123-456-7890"
}