Assume that I need to insert a record in my DB which has a foreign key constraint to another entity for which the client supplies a non existent id.
Obviously I check for the existence of the mentioned foreign key. Should I return the 404 status code or is something like 422 - Unprocessable Entity a more suitable response code?
According with https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5, 404 is used in case:
- The request-uri was not match
- he server doesn't want to reveal why the request has been refused
- No other response is applicable
Therefore, I would use 422.
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