So the HTTP spec says that HTTP PUT and DELETE should be idempotent. Meaning, multiple PUT requests to the same URL with the same body should not result in additional side-effects on the server. Same goes with multiple HTTP DELETEs, if 2 or more DELETE requests are sent to the same URL, the second (or third, etc) requests should not return an error indicating that the resource has already been deleted.
However, what about PUT requests to a URI after a DELETE has been processed? Should it return 404?
For example, consider the following requests are executed in this order:
- POST /api/items – creates an
itemresource, returns HTTP 201 and URI /api/items/6 - PUT /api/items/6 – updates the data associated with
item#6 - PUT /api/items/6 – has no side effects as long as request body is same as previous PUT
- DELETE /api/items/6 – deletes
item#6 and returns HTTP 202 - DELETE /api/items/6 – has no side effects, and also returns HTTP 202
- GET /api/items/6 – this will now return a 404
- PUT /api/items/6 – WHAT SHOULD HAPPEN HERE? 404? 409? something else?
So, should PUT be consistent with get and return a 404, or like @CodeCaster suggests, would a 409 be more appropriate?
And:
So to define ‘appropriate’ is to look at the 400-series, indicating there’s a client error. First I’ll eliminate the irrelevant ones:
syntax.
according to the accept headers sent in the request.
client must first authenticate itself with the proxy.
Length.
So, which ones may we use?
This description actually fits pretty well, altough it is usually used in a permissions-related context (as in: YOU may not …).
This one too, especially the last line.
There are no valid methods we can respond with, since we don’t want any method to be executed on this resource at the moment, so we cannot return a 405.
But that assumes there already is a resource at the URI (how can there be a conflict with nothing?).
This one also makes sense.
I’ve edited this post a few times now, it was accepted when it claimed "use 410 or 404", but now I think 403 might also be applicable, since the RFC doesn’t state a 403 has to be permissions-related (but it seems to be implemented that way by popular web servers). I think I have eliminated all other 400-codes, but feel free to comment (before you downvote).