What HTTP status code is better to use in the following case?
I have a REST API to get some database entity basing on its id. The case is when the requested entity cannot be found in the database.
What HTTP status code is better to use in the following case?
I have a REST API to get some database entity basing on its id. The case is when the requested entity cannot be found in the database.
I tend to use 404. That being said here's a wikipedia link for HTTP status codes https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
404
is the status code suitable for this situation. It indicates a client error and indicates that a representation cannot be found for requested resource.
From the RFC 7231, the document that defines the semantics of the HTTP/1.1 protocol:
The
404
(Not Found) status code indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists. A404
status code does not indicate whether this lack of representation is temporary or permanent; the410
(Gone) status code is preferred over404
if the origin server knows, presumably through some configurable means, that the condition is likely to be permanent.