DELETE is supposed to be idempotent.
If I DELETE http://example.com/account/123 it's going to delete the account.
If I do it again would I expect a 404, since the account no longer exists? What if I attempt to DELETE an account that has never existed?
I think the same thing, 404 - Account doesn't exist.
You could argue 400 - Bad Request. But in the sense of REST the object you requested to perform an action on doesn't exist. That translates to 404.
Idempotence refers to the state of the system after the request has completed
In all cases (apart from the error issues - see below), the account no longer exists.
From here
The key bit there is the side-effects of N > 0 identical requests is the same as for a single request.
You would be correct to expect that the status code would be different but this does not affect the core concept of idempotency - you can send the request more than once without additional changes to the state of the server.
Yes. Regardless of the response code.
From latest RFC for HTTP 1.1 (emphasis mine):
It explicitly says that the response might differ. More importantly, it points out the reason of the concept: if an action is idempotent, the client can repeat the action when it encounters any error, and knows that it won't crash anything by doing so; if not, the client will have to make an additional query (possibly
GET
) to see whether the previous one is effective, before it safely repeat the action. As long as the server can make such guarantee, the action is idempotent. Quote from another comment:Idempotent is about the effect of the request, not about the response code that you get.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.2 says:
While you may get a different response code, the effect of sending N+1 DELETE requests to the same resource can be considered to be the same.
The important distinction is that idempotent refers to side-effects, not all-effects or responses. If you do a
DELETE http://example.com/account/123
then the effect is that account 123 is now deleted from the server. That is the one and only effect, the one and only change to the state of the server. Now lets say you do the sameDELETE http://example.com/account/123
request again, the server will respond differently, but its state is the same.Its not like the DELETE request decided to change the server state in a different way because the account was missing, such as removing another account, or leaving an error log. Nay, you could call the same DELETE request a million times and you can be sure that the server is in the same state as it was the first time you called it.
From the HTTP RFC:
Note that's "side effects", not "response".