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
Asked
Active
Viewed 4.7k times
81

KlsLondon
- 1,160
- 1
- 9
- 18
-
Maybe pick the appropriate one from here? http://www.w3.org/Protocols/HTTP/HTRESP.html – Hanky Panky Jul 26 '13 at 14:50
-
11I found this flow chart to be enlightening: http://i.stack.imgur.com/whhD1.png – huwr Jan 08 '15 at 05: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?
= Yes -> – unomi Oct 05 '15 at 07:18= Yes -> 204 No Content (??) Looks like the Yes / No paths are swapped there?
3 Answers
110
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.

George John
- 2,629
- 2
- 21
- 16
-
4
-
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`. – Manuel Jordan Apr 10 '17 at 18:06
-
1Thx. 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. – robkrueger Sep 19 '18 at 11:13
-
I disagree with returning 204 in this case. As the standard says ( https://www.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. – FishingIsLife Aug 18 '20 at 07:25
-
1@FishingIsLife Please, [bury RFC 2616](https://www.mnot.net/blog/2014/06/07/rfc2616_is_dead). It was long-time ago replaced by RFC 7230-7235. I.e. [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-4.3.5) 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 – Roman Vottner Oct 31 '21 at 20:27
45
Yes, it would be 404.
In general it will be a 400 series error if the request is wrong somehow, and a 500 series error if something goes awry on the server.

Will Hartung
- 115,893
- 19
- 128
- 203
-1
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.

Erik Philips
- 53,428
- 11
- 128
- 150