0

I have a resource called Logins, and I invoke a GET via AJAX from the browser. The current behavior is to return a 404 when the specific login cannot be found.

I'm using this to check whether a username is in use or not. (when creating a new user, the username must be unique)

http://localhost/Logins/Matthew

The AJAX code works fine and can read the response's status code, however, the browser's (firefox) console flags it as an error (all 404s are). This leads me to believe that it may not be the best idea to give non-successful type responses to browsers.

I'd rather not have the browser treat this as an exceptional case and flag it as an error in the console, mainly because it's alarming when the developer tools light up.

Should I:

  1. Ignore the console, 404s are perfectly valid in this case.
  2. Avoid using 4xx status code responses and return a less 'restful' response.
  3. Change the resource as Logins doesn't make sense for the use-case.
  4. Something else...

Browsers are the only consumer of this API, so I can change it anyway that best suits them.

2

1 Answer 1

4

404 is perfectly fine for this use case. 4xx status codes are client error codes, so browser treats them as such, and that is perfectly fine too.

Another kind of APIs (e.g. JSON-RPC) use different approaches, but since you're going RESTful, do not change response code just to make console output look pretty - it is not a use case, users are not supposed to inspect console output.

1
  • This was one of my thoughts on the subject, and it sounds like it's the way to go, however, I'm going to wait a bit to see if there's any opposing viewpoints.
    – Matthew
    Commented Apr 14, 2015 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.