News for hackers. Stuff that matters.
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:

      {
         "baz": "boo"
      }
DELETE would remove baz, PATCH would change baz, and PUT would, in effect, remove foo.
Re:What Is JSON Patch? by toomim on Tuesday May 10, 2022 @02:38AM (#31324165)
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

Re:What Is JSON Patch? by gregorty on Tuesday May 10, 2022 @03:31AM (#31324500)
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.
Re:What Is JSON Patch? by Sharparam on Tuesday May 10, 2022 @05:32AM (#31325120)
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.

Re:What Is JSON Patch? by toomim on Tuesday May 10, 2022 @10:36PM (#31335251)
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.
Re:What Is JSON Patch? by fortylove on Tuesday May 10, 2022 @02:36AM (#31324147)
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.
Re:What Is JSON Patch? by ratww on Tuesday May 10, 2022 @04:40AM (#31324866)
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.