Common HTTP Status Codes

HTTP Status Codes
The HTTP status codes can be used to indicate a successful or an error response for API’s

2xx class (Success)
This class of status codes indicates the action requested by the client was received, understood, accepted and processed successfully.

3xx class (Redirection)
This class of status code indicates the client must take additional action to complete the request. Many of these status codes are used in URL redirection.

4xx class (Client error)
The 4xx class of status code is intended for cases in which the client seems to have errored. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method.

5xx class (Server error)
The server failed to fulfil an apparently valid request.
Response status codes beginning with the digit “5” indicate cases in which the server is aware that it has encountered an error or is otherwise incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and indicate whether it is a temporary or permanent condition.

Code Message Description
200  OK Response to a successful GET, PUT, PATCH or DELETE. Can also be used for a POST that doesn’t result in a creation.
201 Created Response to a POST that results in a creation. Should be combined with a Location header pointing to the location of the new resource
204  No Content Response to a successful request that won’t be returning a body (like a DELETE request)
304  Not Modified Used when HTTP caching headers are in play
400  Bad Request The request is malformed, such as if the body does not parse. Any application related errors can be reported here with proper error code and description.
401  Unauthorized When no or invalid authentication details are provided. Also useful to trigger an auth popup if the API is used from a browser
403  Forbidden When authentication succeeded but authenticated user doesn’t have access to the resource
404 Not Found  When a non existent resource is requested
405  Method Not Allowed When an HTTP method is being requested that isn’t allowed for the authenticated user
409 Conflict Indicates that the request could not be processed because of conflict in the request, such as an edit conflict in the case of multiple updates.
410  Gone Indicates that the resource at this end point is no longer available. Useful as a blanket response for old API versions
413 Request Entity Too Large The request is larger than the server is willing or able to process.
414 Request URI too long The URI provided was too long for the server to process. Often the result of too much data being encoded as a query-string of a GET request, in which case it should be converted to a POST request.
415 Unsupported Media Type If incorrect content type was provided as part of the request
422 Unprocessable Entity Used for validation errors
429 Too Many Requests When a request is rejected due to rate limiting
500 Internal Server Error A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
501 Not Implemented The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API)
502 Bad Gateway The server was acting as a gateway or proxy and received an invalid response from the upstream server.
503 Service Unavailable The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.
504 Gateway Timeout The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Common HTTP Status Codes

  1. Pingback: REST API Best practices | saipraveenblog

  2. Pingback: Rest API best practices | My Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s