Essential HTTP Codes
Posted by Anandhan Subbiah on May 12, 2009 in Programming Concepts, Technical Articles • 1 comment200 (”OK”)
Everything’s fine. The document in the entity-body, if any, is a representation of some resource.
400 (”Bad Request”)
There’s a problem on the client side. The document in the entity-body, if any, is an error message. Hopefully the client can understand the error message and use it to fix the problem.
500 (”Internal Server Error”)
There’s a problem on the server side. The document in the entity-body, if any, is an error message. The error message probably won’t do much good, since the client can’t fix a server problem.
There are four more error codes that are especially common in web services:
301 (”Moved Permanently”)
Sent when the client triggers some action that causes the URI of a resource to change. Also sent if a client requests the old URI.
404 (”Not Found”) and 410 (”Gone”)
Sent when the client requests a URI that doesn’t map to any resource. 404 is used when the server has no clue what the client is asking for. 410 is used when the server knows there used to be a resource there, but there isn’t anymore.
409 (”Conflict”)
Sent when the client tries to perform an operation that would leave one or more resources in an inconsistent state.
200 (”OK”)
In most cases, this is the code the client hopes to see. It indicates that the server successfully carried out whatever action the client requested, and that no more specific code in the 2xx series is appropriate. My bookmarking service sends this code, along with a representation, when the client requests a list of bookmarks.
Entity-body: For GET requests, a representation of the resource the client requested. For other requests, a representation of the current state of the selected resource, or a description of the action just performed.
201 (”Created”)
The server sends this status code when it creates a new resource at the client’s request. My bookmarking service sends this code in response to a POST request that creates a new user account or bookmark.
Response headers: The Location header should contain the canonical URI to the new resource.
Entity-body: Should describe and link to the newly created resource. A representation of that resource is acceptable, if you use the Location header to tell the client where the resource actually lives.
307 (”Temporary Redirect”)
The request has not been processed, because the requested resource is not home: it’s located at some other URI. The client should resubmit the request to another URI.
For GET requests, where the only thing being requested is that the server send a representation, this status code is identical to 303 . A typical case where 307 is a good response to a GET is when the server wants to send a client to a mirror site. But for POST, PUT, and DELETE requests, where the server is expected to take some action in response to the request, this status code is significantly different from 303.
A 303 in response to a POST, PUT, or DELETE means that the operation has succeeded but that the response entity-body is not being sent along with this request. If the client wants the response entity-body, it needs to make a GET request to another URI.
A 307 in response to a POST, PUT, or DELETE means that the server has not even tried to perform the operation. The client needs to resubmit the entire request to the URI in the Location header.
An analogy may help. You go to a pharmacy with a prescription to be filled. A 303 is the pharmacist saying “We’ve filled your prescription. Go to the next window to pick up your medicine.” A 307 is the pharmacist saying “We can’t fill that prescription. Go to the pharmacy next door.”
Response headers: The Location header contains the URI to which the client should resubmit the request.
Entity-body: Should contain a hypertext document linking to the new URI, as with 301.
400 (”Bad Request”)
This is the generic client-side error status, used when no other 4xx error code is appropriate. It’s commonly used when the client submits a representation along with a PUT or POST request, and the representation is in the right format, but it doesn’t make any sense.
Entity-body: May contain a document describing why the server thinks there’s a client-side error.
401 (”Unauthorized”)
The client tried to operate on a protected resource without providing the proper authentication credentials. It may have provided the wrong credentials, or none at all. The credentials may be a username and password, an API key, or an authentication token—whatever the service in question is expecting. It’s common for a client to make a request for a URI and accept a 401 just so it knows what kind of credentials to send and in what format. In fact, the HTTP Digest mode of authentication depends on this behavior.
If the server doesn’t want to acknowledge the existence of the resource to unauthorized users, it may lie and send a 404 (”Not Found”) instead of a 401. The downside of this is that clients need to know, in advance, what kind of authentication the server expects for that resource: things like HTTP Digest won’t work.
Response headers: The WWW-Authenticate header describes what kind of authentication the server will accept.
Entity-body: A document describing the failure: why the credentials (if any were provided) were rejected, and what credentials would be accepted. If the end user can get credentials by signing up on a web site, or creating a “user account” resource, a link to the sign up URI is useful.
Reference : RESTful Web Services
by Leonard Richardson; Sam Ruby

503 Service Unavailable
504 Gateway Timeout
are two of my favorites when apache fcgi / modXXX apps are slow to respond or proxies can’t contact the origin. Common errors when you front you app with apache/squid and your app restarts or dies