Imagine the following situation:
- You have an HTML sign up form for a user.
- One of the fields is for the user’s email.
- The user fills in the data and POSTs the response to the server.
- The server rejects the request, perhaps the email address is already taken.
Is there an appropriate HTTP status code for this? It seems to me this falls into the 4xx range since the client provided invalid data. Its not a 400 though since the server understood the request. And none of the other 4xx codes seem to fit.
I ran into a similar situation today, except that I’m doing it via an XmlHttpRequest. When posting some data to the server, the request always returns HTTP status code 200 whether or not data was actually inserted into the backend database. Thus, the server has to return back a response that tells the client what happened – probably via a little bit of JavaScript. But it seems like using an HTTP status code would be a much cleaner solution.
Any ideas? Or am I trying to misuse HTTP status codes?
Update – I’ve happily found my answer. A similar problem was posted by Jan Algermissen on the Yahoo Rest discussion list. Bill de hora answered use a new HTTP status code, 418. And in response to that, Roy Fielding, one of the authors of HTTP specification, asked if he should standardize it. Yes please.
Now, let’s see what happens when I try this trick with the browsers.