HTTP PATCH: Handling arrays, deletion, and nested key creation

前端 未结 1 1127
萌比男神i
萌比男神i 2021-02-18 16:29

I\'m looking for a practical guide to implementing the PATCH verb for partial updates of a noun in a RESTful api using JSON. Understanding that PATCH i

1条回答
  •  遇见更好的自我
    2021-02-18 16:58

    The spec clearly details how to format the JSON body of a PATCH request. You're using a totally different format. Given that, I'm not surprised at all that there is ambiguity. The body should look something like:

       [
         { "op": "replace", "path": "/name", "value": "SimpleGuy" },
         { "op": "add", "path": "/email", "value": "hey@google.com" },
         { "op": "replace", "path": "/city", "value": null },
         { "op": "replace", "path": "/roles", "value": [ "owner" ] },
         { "op": "add", "path": "/posts/02/title", "value": "how to pop lock" },
         { "op": "add", "path": "/posts/", "value": "03" },
         { "op": "add", "path": "/posts/03/title", "value": "how to salsa" },
         { "op": "add", "path": "/notes", "value": { "title": "a note title" } }
       ]
    

    Go back and read the spec. It even gives examples which address most of your questions.

    0 讨论(0)
提交回复
热议问题