Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

At my work, we have had arguments about what searches in an REST API should return in the case that no results (literally, in our parlance, "no documents") were found. Is that a 404 or a 200?


Via the W3 spec:

> The request has succeeded. The information returned with the response is dependent on the method used in the request, for example:

Is a query that turns up no documents when there is indeed no documents a success? I would argue yes, as the search service executed the query accurately...in fact, if the query turned up documents when it shouldn't have, that would probably be a problem...

But the way the 404 is worded, it would also fulfill the meaning of "no results".

> The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.


Does your search page display a list of results, or does it redirect to the best result? If the former, I'd say that a list of zero is still a valid search results 'document', and should therefore return a 200. But the latter could certainly return a 404, although I doubt that's how your search actually works :)


Haha, that is the sort of argument I'd avoid having at work because it would lead to bloodshed.


Either would arguably be a reasonable choice, and therefore you should use whichever is going to be more convenient for the actual use cases you know about.

Which is almost always 200. Partially because that's what everyone will expect because that's what everyone else does.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: