Several servers I have dealt with will return HTTP 200 for requests that the client ought to consider a failure, with something like 'success : false' in the body.
This does not seem like a proper implementation of HTTP codes to me, particularly in cases of failed authentication. I have read HTTP error codes pretty succinctly summed up as, '4xx' indicates that the request should not be made again until changed, while '5xx' indicates that the request may or may not be valid and can be retried, but was unsuccessful. In this case 200: login failed, or 200: couldn't find that file, or 200: missing parameter x, definitely seem wrong.
On the other hand, I could see the argument being made that '4xx' should only indicate a structural issue with the request. So that is proper to return 200: bad user/password rather than 401 unauthorized because the client is permitted to make the request, but it happens to be incorrect. This argument could be summarized as, if the server was able to process the request and make a determination at all, the response code ought to be 200, and it's up to the client to check the body for further information.
Basically, this seems to be a matter of preference. But that is unsatisfying, so if anyone has a reason why either one of these paradigms is more correct, I would like to know.
success: false
implies that the request failed and you know it. That should be a 500. Something like your bad username/password would be a 401. This isn't that ambiguous.success: false
does NOT imply the request itself failed. When dealing with web applications, the request is often NOT a simple "GET" request for a document identified by a URL. Rather the request is more often a POST to a remote method in an application (i.e. a remote procedure call). If anything, it's more like a "TRY GET", and you can't even use the HTTP GET verb because you can't post, for example, a JSON payload for the method to consume.success: false
is NOT a 500. As a 500, an AJAX request through jQuery would not even be able to process the payload, as it considers anything other than a 200 (or 301 found) as a failure and invokes a failure handler. If the request makes it to the server, finds the right procedure, executes, and returns a valid, formatted response for the application... that's a 200. Always. Period.