Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 404 status code suitable for a non existent entity upon insertion?

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?

like image 336
2hamed Avatar asked Oct 23 '25 16:10

2hamed


1 Answers

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.

like image 98
Diego Honma Avatar answered Oct 26 '25 11:10

Diego Honma