Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP status code for inability to process request

Making a delete request to /api/ingredients/123 endpoint.

If ingredient 123 didn't exist, I expect I should return a 404 Not Found status code. Agree?

What if ingredient 123 did exist, but was used in an existing recipe so it couldn't be deleted. What status code should be returned?

like image 365
user1032531 Avatar asked Nov 07 '25 22:11

user1032531


1 Answers

409 Conflict

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.

In your case, an ingredient cannot be deleted as it is used (conflicting state of the resource) in one or more recipes. But once the ingredient is out of use it can be deleted.

like image 148
Saikrishna Radarapu Avatar answered Nov 09 '25 17:11

Saikrishna Radarapu



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!