1

Just a basic question on REST web services HTTP DELETE method. As per HTTP protocol documentation, DELETE is idempotent. But first time we send, you get 200 response code and subsequent requests you get 404 error as that resource does not exist. So, why would it be called idempotent if the response is different?

John Mulder
  • 9,765
  • 7
  • 33
  • 37
Krishna
  • 11
  • 2
  • 1
    Same question here : http://stackoverflow.com/questions/4088350/is-rest-delete-really-idempotent – Michel Oct 10 '15 at 18:15

2 Answers2

5

The deprecated HTTP spec (RFC2616) used some loose language around the description of idempotency that has led to this confusion. The newer RFC 7231 says it much better:

4.2.2. Idempotent Methods

A request method is considered "idempotent" if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request. Of the request methods defined by this specification, PUT, DELETE, and safe request methods are idempotent.

Note the bolded text "on the server". Idempotency doesn't dictate what is returned, it cares about the effect of the request on the system.

Community
  • 1
  • 1
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
1

There is an answer on REST API Tutorial :

There is a caveat about DELETE idempotence, however. Calling DELETE on a resource a second time will often return a 404 (NOT FOUND) since it was already removed and therefore is no longer findable. This, by some opinions, makes DELETE operations no longer idempotent, however, the end-state of the resource is the same. Returning a 404 is acceptable and communicates accurately the status of the call.

Michel
  • 490
  • 4
  • 11