I have a resources with uri /api/books/122 , if this resource doesn't exist at the point where a client sends HTTP Delete for this resource, what is the appropriate response code from this action? Is it 404 Not Found?
Thanks
-
Maybe pick the appropriate one from here? w3.org/Protocols/HTTP/HTRESP.htmlHanky Panky– Hanky Panky2013-07-26 14:50:05 +00:00Commented Jul 26, 2013 at 14:50
-
13I found this flow chart to be enlightening: i.sstatic.net/whhD1.pnghuwr– huwr2015-01-08 05:15:42 +00:00Commented Jan 8, 2015 at 5:15
-
@huwr Is there an editable source for this somewhere? Also - Am I wrong to think that there is a mistake at the bottom center? <Deleted> = Yes -><Response Includes an Entity> = Yes -> 204 No Content (??) Looks like the Yes / No paths are swapped there?unomi– unomi2015-10-05 07:18:26 +00:00Commented Oct 5, 2015 at 7:18
Add a comment
|
3 Answers
The response code for a delete call can be any of the following :
DELETE /api/book/122- The server successfully processed the request, but is not returning any content204 No Content
DELETE /api/book/122- Resource does not exist404 Not Found
DELETE /api/book/122- Resource already deleted410 Gone
DELETE /api/book/122- Users does not have permission403 Forbidden
DELETE /api/book/122- Method Not Allowed405 Method Not Allowed
DELETE /api/book/122- Conflict (User can resolve the conflict and delete)409 Conflict
In your case 404 is apt.
5 Comments
maikel
Can you share the references for this?
Manuel Jordan
About an
URI for either Delete or Update and assuming the scenario where the resource does not exist anymore, I think should be 410 (Gone). But consider the scenario if the resource never existed from the beginning or previously, there has more sense the 404.robkrueger
Thx. What would be an appropriate response code if, let's say the resource exists but cannot be deleted due to some child-data, other references, or any such condition that prevents it from beeing deleted? In that case, the request URL is technically correct and the user would have the right to do so if the other preconditions weere to be met.
FishingIsLife
I disagree with returning 204 in this case. As the standard says ( w3.org/Protocols/rfc2616/rfc2616-sec10.html ) a 204 should not change the clients view. But if you delete the book this would result in a reload of a view with a new book list without the deleted book.
Roman Vottner
@FishingIsLife Please, bury RFC 2616. It was long-time ago replaced by RFC 7230-7235. I.e. RFC 7231 explicitely lists the admissible status codes one should return on a successful DELETE request. The request itself is also just a request to remove the association for the link to the resource but does not necessarily have to lead to a resource deletion as well. I often time will, but it does not necessarily have to. There is a fine difference in the semantics
I would suggest taking a look at this flow diagram. It's obviously a little bit more than you need but a great resource for future readers. Sadly there is no excerpt possible.
