Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is appropriate http status code for database operation failure? [duplicate]

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 467
KlsLondon Avatar asked Mar 20 '26 15:03

KlsLondon


2 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 76
George John Avatar answered Mar 22 '26 03:03

George John


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.

like image 20
Will Hartung Avatar answered Mar 22 '26 04:03

Will Hartung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!