Re:What Is JSON Patch?
by gregorty on Tuesday May 10, 2022 @02:31AM
(#31324114)
Sending it with different HTTP verbs might do the trick. For your example:
DELETE would remove baz, PATCH would change baz, and PUT would, in effect, remove foo.
[ Parent
| on HN ]
That doesn't work, because DELETE is defined to delete the entire resource. PUT is defined to replace the resource with the body, which would replace the resource with the patch. Only PATCH is defined to accept a patch and do something special with it.
Another option, though, is to use the Range-Patch spec from: https://github.com/braid-org/braid-spec
DELETE doesn't have to remove the entire resource, it's up to the receiving service on how to implement it.
Re:What Is JSON Patch?
by actually_a_dog on Tuesday May 10, 2022 @05:04AM
(#31324982)
Exactly. I have issues with this approach, but "DELETE is defined to..." is not one of them. DELETE does whatever the fuck you want it to.
Abusing HTTP methods like this is something ElasticSearch does on some of their APIs. This is annoying because spec-compliant tools don't always play nice with them.
For example: ElasticSearch can take a body on some GET requests, but many tools will not let you do this because a GET request should not have a body.
If you have a proxy, cache, or middlebox in your network, and you use DELETE to mean "remove this key from the JSON object" your proxy won't know that, and will happily delete the entire resource, and tell everyone else that the resource has been deleted, and then your data will disappear, and that's not very fun.
What if you want to delete one attribute, and update another, within the same request? Seems like utilizing HTTP DELETE would not work well for this, unless you can specify it at the attribute level, leading you back towards something like JSON Patch.
Yep. Another common case is appending to an inner array vs replacing that array.
Re:What Is JSON Patch?
by dragonwriter on Tuesday May 10, 2022 @05:06AM
(#31324993)
DELETE, per spec, does not take a body and any body it does have is ignored.