Do repeated requests to idempotent methods have to return the same response code?
A lot of other people are asking the same question and ending up with contradicting answers. The answer should reference an authoritative source on the matter.
Implemented correctly, the GET , HEAD , PUT , and DELETE methods are idempotent, but not the POST method.
Non-idempotent (PUT,POST,DELETE) methods change the data which is used to populate content in the web pages or effect change elsewhere (such as moving a crane, transferring funds, sending an email). That's not entirely correct. Idempotent means that you can repeat the request and the result should be the same.
Idempotency means that multiple identical requests will have the same outcome. So it does not matter if a request is sent once or multiple times. The following HTTP methods are idempotent: GET, HEAD, OPTIONS, TRACE, PUT and DELETE. All safe HTTP methods are idempotent but PUT and DELETE are idempotent but not safe.
An idempotent method means that the result of a successful performed request is independent of the number of times it is executed.
I asked this question on the HTTP mailing list and was told that idempotency does not include return codes. Meaning, you are free to return HTTP 204 the first time a resource is deleted, and HTTP 404 at a later time, so long as the subsequent request does not change the server state.
While it is true that subsequent requests may not change the server state, the response codes are not considered part of that state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With