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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With