HTTP Response for Unsuccessful Handling of Request

http, http-status-codes, rest

Solution

That is very easy.

404 Not Found

If there is no resourece at `/id/42`, a resource can not be found for this URL.

See the list of HTTP status codes.

Problem

Let's say I have a REST `POST` end-point: `www.foo.com/id/X` where `X` represents a number. My server-side pseudocode looks like this: ``` performIdLookup(int id) { if ( idExists(id) ) { return toJson(lookup(id)) // returns 200/OK Status Code with object as JSON } else { return HTTP_???_error } } ``` Per this question, sending a `400` error doesn't seem right here since the user submitted a valid request, but the server couldn't locate it. What's the right HTTP response here and why?

Original source

Related problems