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?
Re: HTTP status code in response to the condition that ingredient 123 didn't exist [and never did exist]; yes, I agree that the 404 - Not Found - is correct.
If ingredient 123 did exist and is now deleted, then 410 - Gone - is appropriate. (My website uses the 410 status code for obsolete products.)
However, your case has ingredient 123 existing, but that the delete request for that specific ingredient cannot be processed due to a data dependency conflict ("an existing recipe"). For this case, 405 - Method Not Allowed - is appropriate.
HTTP status of 405 indicates that the ingredient reference is OK, but not the delete request.
Wikipedia and w3.org have helpful pages on HTTP status codes.