3 ms·
Sending it with different HTTP verbs might do the trick. For your example: { "baz": "boo" } DELETE would remove baz, PATCH would change b
by gregorty 4y ago
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.
- fortylove 4y agoWhat 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.
- ratww 4y agoYep. Another common case is appending to an inner array vs replacing that array.
- toomim 4y agoThat 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 https://github.com/braid-org/braid-spec
- gregorty 4y agoDELETE doesn't have to remove the entire resource, it's up to the receiving service on how to implement it.
- actually_a_dog 4y agoExactly. 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.
- Sharparam 4y agoAbusing 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.
- toomim 4y agoIf 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.
- deleted 4y ago[deleted]
- dragonwriter 4y agoDELETE, per spec, does not take a body and any body it does have is ignored.