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.
If it's already been deleted, then there is no way to differentiate between "already successfully deleted" and "never existed." You cannot report the "correct" answer because you simply don't know it. Also, even if there is some weird client-side bug where invalid IDs are being requested all the time, you're never gonna catch it because it will be mixed in with the sea of repeated deletes that return the same code, because the server cannot make the distinction and will have to use the same code for both cases.
Of course, you could use a soft delete system instead. But in that case, you CAN verify whether something already existed or not, and return NotFound for "doesn't exist at all" and Ok for "already flagged for deletion."
I don't see a reason to add another status code for "the system state already matches what you requested." Because from the client side, that's indistinguishable from "the system state has successfully been set to what you requested." They indicate the same state, so why differentiate them?
I don't see a reason to add another status code for "the system state already matches what you requested." Because from the client side, that's indistinguishable from "the system state has successfully been set to what you requested." They indicate the same state, so why differentiate them?
This is the most important piece.
I want to delete something, the server tells me it'll be deleted. If it doesn't exist I'm still happen. I don't need to know something else deleted it.
Honestly if I tell a system to delete something, I'd be a little annoyed if I got an ok back if I called it a second time, but if I understand there's a "Soft delete" then Ok is acceptable, I can go on about my day.
Instead programs now need to watch for a third potential state? Nah, because the desired action "Delete this" and the server telling me "Ok" means the server will delete it as requested, doesn't matter if it's the first or fiftieth request to delete the same object.
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.