3. Example (示例)
3. Example (示例)
给定以下示例 JSON 文档:
{
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
}
用户代理希望将 "title" 成员的值从 "Goodbye!" 更改为 "Hello!", 添加一个新的 "phoneNumber" 成员, 从 "author" 对象中删除 "familyName" 成员, 并替换 "tags" 数组使其不包含单词 "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 文档将是:
{
"title": "Hello!",
"author" : {
"givenName" : "John"
},
"tags": [ "example" ],
"content": "This will be unchanged",
"phoneNumber": "+01-123-456-7890"
}