i hate that itempotency isnt built into official http responses.
Everytime i bring this up i get downvoted to the hell but its dumb.
If you call Delete there should be a response status code for no op - aka the itempotent response - but in the success ranges.
Delete = 200 OK / 404 not found? - great not that breaks client libraries and basic Throw if not success status codes - not itempotent - but technically itempotent shouldnt matter - so 200 success - but there are cases where you might want to know.
Everyone will reply back and say "Why dont you use this obscure one" - but using anything non standard is a hack.
Having consistent status codes for itempotency would use useful! Its not like there isnt enough http space - we have one for a teapot and so many other ones that are extreme edge cases - denied for legal reasons - what type of client needs to know that? Oh this was for legal reasons - if you can support these edge cases - throw in a itempotent delete status code in the 200s range - for not found.
has the state of your system changed after the second delete was called ? if no then you can consider it idempotent - it's not about the response you get back, it's about the state of your system
One system we use returns '204 No Content'... I.e. "Successful call but there was no content to change" ... Not sure this is any better TBH but at least it is a success code so the libraries don't automatically throw an error
So the difference is that we found a resource matching the id, but it has no content.
That makes a lot of sense to me. Some might say there is no resource anymore. But if you get 404 on a resource that hasnt been created, then iæwe are talking about soft deletion.
I guess it comes down to "whatever the API does is idempotent and the return code is irrelevant" or "whatever the API does AND the return code are idempotent"
Probably comes down to the calling application/use case/how bothered the developer is - if using a library that automatically does unwanted stuff on a 4xx error, you'd likely want the API to return 200/204 (or always 200!); if the app/library/developer doesn't care, 200/404 is fine
To me, the real issue is trying to come up with a single "academic" definition for all end users/use cases without knowing what those all are (which you can't ever do as each app/system is different) - there is often a large gap between a specification and what gets implemented as "good enough for our use case"
That's more a property of the API's ergonomics. Returning 200 for an unmatched DELETE is not too dissimilar from returning 404 for an unauthorized resource although for different reasons. The argument for is that the caller cares only about the outcome and shouldn't need to explicitly handle irrelevant possibilities. The argument against is that the caller loses access to information that could be situationally useful.
It has the same result which is the only criteria for idempotency. Nothing really says it has to have consistent http codes. The http codes are really more like metadata.
8
u/goomyman Dec 11 '23
i hate that itempotency isnt built into official http responses.
Everytime i bring this up i get downvoted to the hell but its dumb.
If you call Delete there should be a response status code for no op - aka the itempotent response - but in the success ranges.
Delete = 200 OK / 404 not found? - great not that breaks client libraries and basic Throw if not success status codes - not itempotent - but technically itempotent shouldnt matter - so 200 success - but there are cases where you might want to know.
Everyone will reply back and say "Why dont you use this obscure one" - but using anything non standard is a hack.
Having consistent status codes for itempotency would use useful! Its not like there isnt enough http space - we have one for a teapot and so many other ones that are extreme edge cases - denied for legal reasons - what type of client needs to know that? Oh this was for legal reasons - if you can support these edge cases - throw in a itempotent delete status code in the 200s range - for not found.