3 ms·
A race shouldn't matter so long as both succeed at least once; that would have the same effect as if either/both had succeeded multiple times. The only differen
by SilasX 11y ago
A race shouldn't matter so long as both succeed at least once; that would have the same effect as if either/both had succeeded multiple times. The only difference is whether the user is informed of whether a related action obviated their request, which is going to happen anyway.
Edit: turns out I was wrong and assumed PUT should fail if the resource doesn't exist, which isn't how it works. (Probably because of writing apps that deprecate it in favor of PATCH.)
- Someone 11y agoShouldn't matter? DELETE foo/bar PUT foo/bar If that delete gets a retry, actual execution order could be PUT foo/bar DELETE foo/bar Or am I misunderstanding this?
- SilasX 11y agoIt doesn't matter: as I said, that has the same end state (no foo/bar resource), the only possible difference is response code i.e. whether (in this case) you get to learn that your update doesn't matter.
- marcosdumay 11y agoThe first sequence ends with foo/bar existing. The second one ends with it not existing. I'd say that anybody that sends a pair of PUT/DELETE requests in fast succession over the web and expects a stable result is a fool. This should have no effect on practice, because nobody should be relying on the ordering anyway.
- SilasX 11y agoAh, my mistake. I had always equated PUT with updating and assumed it should fail if it doesn't find the resource. Big oversight!
- rbw 11y agoI think you're correct, actually. If you want to create a new object, it should be a POST. In a well designed RESTful service, a PUT on an object that doesn't exist should fail, and both of the PUT/DELETE orderings above should result in the same state of the world: the object does not exist.
- SilasX 11y agoI thought so too, but when I looked at the spec [1], it agreed with the others: >>The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI [1] https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html 9.6
- rbw 11y agoSounds like the others are indeed correct. Thanks for the citation!
- thedufer 11y agoYou're probably thinking of PATCH. In many, if not most, RESTful services, PUT is given PATCH semantics. PUT is supposed to be insert-or-update.
- rbw 11y agoAh, I stand corrected. Thanks!
- dragonwriter 11y ago> A race shouldn't matter so long as both succeed at least once; that would have the same effect as if either/both had succeeded multiple times. Idempotence only means that the same single method repeated additional times on its own will not produce different end states. It doesn't necessarily guarantee this for combinations of methods in different orderings. It doesn't stop PUT/DELETE/PUT/DELETE from having different results than PUT/DELETE/DELETE/PUT to the same resource. (You can do assure that these are equivalent in a particular HTTP-compliant application, but it goes beyond the base semantics of HTTP to do so.)
- SilasX 11y agoI was only saying there that the combination didn't create other problems (due to race conditions), not that that fact was related to idempotence. Though it happens to be true for the combination of PUT/DELETE as well! I think you're equating my claims about what methods are idempotent with my claims about what reorderings matter.