Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the HTTP response code for failed HTTP Delete operation?

Tags:

rest

http

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

like image 850
KlsLondon Avatar asked Jul 26 '13 14:07

KlsLondon


People also ask

What HTTP response for delete?

A successful response of DELETE requests SHOULD be an HTTP response code 200 (OK) if the response includes an entity describing the status. The status should be 202 (Accepted) if the action has been queued.

Should delete return 404 or 204?

If you DELETE something that doesn't exist, you should just return a 204 (even if the resource never existed). The client wanted the resource gone and it is gone. Returning a 404 is exposing internal processing that is unimportant to the client and will result in an unnecessary error condition.

What is a 201 response code?

The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.


1 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 content
    • 204 No Content
  • DELETE /api/book/122 - Resource does not exist
    • 404 Not Found
  • DELETE /api/book/122 - Resource already deleted
    • 410 Gone
  • DELETE /api/book/122 - Users does not have permission

    • 403 Forbidden
  • DELETE /api/book/122 - Method Not Allowed

    • 405 Method Not Allowed
  • DELETE /api/book/122 - Conflict (User can resolve the conflict and delete)

    • 409 Conflict

In your case 404 is apt.

like image 127
George John Avatar answered Oct 18 '22 05:10

George John