Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right HTTP status code for a response when I can't perform a DELETE due to a FK constrain?

What would be the right response I should give to the users when they try to DELETE an entity on a datasource sitting behind a rest/odata api, and the operation cannot be performed due to a foreign key constrain? Is it a bad request? A not acceptable? A server-side error (>=500)?

like image 293
cazala Avatar asked Oct 20 '15 19:10

cazala


People also ask

What HTTP status code to return for delete?

DELETE API Response Codes. 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.

What is the status code for delete request no content?

If a DELETE method is successfully applied, there are several response status codes possible: A 202 ( Accepted ) status code if the action will likely succeed but has not yet been enacted. A 204 ( No Content ) status code if the action has been enacted and no further information is to be supplied.

Should Put return 200 or 204?

200 OK - This is the most appropriate code for most use-cases. 204 No Content - A proper code for updates that don't return data to the client, for example when just saving a currently edited document. 202 Accepted - If the update is done asynchronous, this code can be used.

What does an HTTP response code of 201 indicate?

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

Just found this website that says that '409 Conflict' should be used when 'the request could not be completed due to a conflict with the current state of the resource' and 'where it is expected that the user might be able to resolve the conflict and resubmit the request', then it gives an example when 'cascade-delete is not supported' which kinda resembles my scenario..

http://www.restapitutorial.com/httpstatuscodes.html

like image 74
cazala Avatar answered Sep 22 '22 12:09

cazala