revalidation

HTTP status codes, meanings, and their applications

HTTP status codes are 3-digit standard codes used to convey the status or result of an HTTP operation. Here a is a comprehensive list of all HTTP status codes, their meanings, and correct usage

200 HTTP response status code

HTTP status codes are 3-digit standard codes used to convey the status of an HTTP operation between two or more parties. As a start, servers and clients rely on the HTTP status code to determine the result of an HTTP operation.

HTTP status codes are also commonly known as HTTP response codes, and this article will be using them interchangeably.

Communication over HTTP, the Hypertext transfer protocol, is communication between web servers and clients that involves transferring packets of data in a stateless form from one to the other.

These packets of data are formatted and are called HTTP messages. It could be a Request message or a Response message. There is also the notion of Inbound and Outbound messages.

An Inbound HTTP message is the flow of an HTTP message to a web server. It characterizes a request from a client to a web server to either retrieve, delete, mutate or store information about a resource.

Outbound flow is the outward flow of data from a web server to a client in response to an inbound message.

This Inbound and Outbound flow of data is also considered by Hosting providers, such as AWS, Google Cloud Platforms, Azure, etc., as they charge for data flow.

HTTP Status Code

When applications communicate over the web, there need to be standardized status codes or signals to indicate HTTP request or operation status. HTTP status codes are 3-digit codes that indicate the status of HTTP operations.

An HTTP request or operation can be in many states. It could be pending, it could error out, it could be in a success state, it could fail, and so many others. This need led to what we call today HTTP Status Codes.

HTTP Status Code is a three-digit code that indicates the status of an HTTP request-response operation.

The nature of HTTP messages

The HTTP message is a simple but formatted data block, either a request message from a web client or an enclosing request-response message from a web server.

HTTP messages consist of three parts:

  1. A start line describing the message
  2. A block of headers containing information about the message (more like metadata)
  3. An optional body containing consumable message data

The Start Line of an HTTP message either says what to do (for a request message) or explains what happened (for a response message).

The second part, a block of headers, describes the content of the message. The headers' block contains fields such as the content length, type, age, and others.

HTTP request and response messages share the same three parts as listed above. Their syntax differs only in the start line.

Payload Entity Body is optional

Note that the entity-body in an HTTP message is optional. The responding server or the requesting client can include no entity data during the communication.

HTTP Request Message Format

Below is the format for an HTTP request message. The start line, which is the first line, contains the Request Method, the Request URL, and the HTTP version.

<Method> <Request-url> <Version>
<Headers>

<Entity-body>

HTTP Response Message Format

Below is the format for an HTTP response message. The response start line contains the HTTP version, the status code, and the reason phrase. The response message format differs from the request message only on the start line.

<Version> <status-code> <reason-phrase>
<Headers>

<Entity-body>

As you can see, The response code, the second entry in the start line of an HTTP response message, is of interest. The third-entry reason phrase is a human-readable version of the status code.

Classification of HTTP Status Codes

There are 5 categories of HTTP status codes based on the type of information the status code relays to the receiving client. The five HTTP status codes categories are:

  1. Informational Status Codes
  2. Success Status Codes
  3. Redirection Status Codes
  4. Client Error Status Codes
  5. Server Error Status Codes

As stated earlier, HTTP status codes are 3-digit codes.

Informational HTTP Status Codes - 1xx

Informational HTTP Status Codes are status codes within 100-199, both inclusive. They are not popular around the internet because they are transitional HTTP headers and were introduced by the HTTP 1.1 protocol.

Servers Implementing just the HTTP 1.0 do not support this range of status codes. Informational HTTP Status Codes are performantly intended to help reduce the burden on web servers.

According to the HTTP 1.1 specification, Implementing Servers, proxies must not send a 1xx response back to HTTP 1.0 clients as they do not support this range of headers.

Note

HTTP 1xx repsonse messages have no entity body. The response message is terminated by an empty line

Below is a list of all the available Informational HTTP Status Codes.

1. Status Code 100 - Continue

Servers send the HTTP 100 status code in response to requests containing an Expect header. The 100 continue status code indicates that everything is OK, and the client can send in the request body.

2. Status Code 101 - Switching Protocol

Servers send this response code if the request has an Upgrade header.

The 101 status code indicates that the Server is switching protocol as requested by the client to one listed in the Upgrade Header.

HTTP Success Status Codes - 2xx

HTTP Success Status Codes are status codes within 200-299, both inclusive. The 200 and 201 status codes are the most commonly used success response codes.

HTTP Success Status Codes indicates that the client's request was successfully received, stored, processed, or retrieved with various kinds of reason phrase depending on the nature of the request, especially the request method.

Find a comprehensive list of all the HTTP Success Status Codes, their reasons, and usage notes below.

1. Status Code 200 - Ok

The 200 status code indicates that the request is ok, was processed successfully, and the Response entity body contains the requested resource.

2. Status Code 201 - Created

The 201 status code Indicates that the entity included in the request payload was created successfully by the server. The 201 status code is sent in response to a POST or PUT request.

The response headers will/should contain a Location header whose value points to the location of the created resource.

3. Status Code 202 - Accepted

The 202 status code Indicates that the request was accepted and queued for processing at a later time. For instance, Batch processing applications return the 202 status code to indicate the successful receipt of instruction.

4. Status Code 203 - Non-Authoritative Information

Proxy agents return a 203 status code to indicate that the information contained in the response has been transformed from that of the origin server's 200 response.

The 203 status code serves as a warning to the recipient that a line proxy has modified the original response body.

5. Status Code 204 - No Content

The 204 status code Indicates that the response message has no entity body but contains a Status-Line and headers.

Browsers would update cache headers for the resource while retaining the resource's previous content. Compared to a 304 response code, these two are similar, except that in a 304 status code, the client should not update its cache with the response headers.

6. Status Code 205 - Reset Content

205 status code applies to mainly HTML forms. The 205 status code tells the User-agent (Browsers) to reset the document that sent the request.

If Implemented, Browsers would reset HTML form fields in the page to their default values when it receives a 205 HTTP Response code.

7. Status Code 206 - Partial Content

HTTP servers return 206 status codes in response to the successful handling of a Range request. 206 status code indicates that the range request was processed successfully, and the entity-body contains the range of data requested.

Range requests/responses are used by video players, file transfers, image processing, and other heavy file processing clients allowing data processing to be handled in chunks and can be buffered.

HTTP Redirection Status Codes - 3xx

When a resource URI or location changes, servers utilize the 3xx response codes to convey information to request clients on the resource's new location.

Redirection status codes or 3xx response codes are HTTP status codes in the 300-399 range, both inclusive. 3xx status codes tell the connected client to use alternate locations for the resource requested.

Coupled with the Location header, Servers can provide the new location of the requested resource. Depending on the response code, it could be a temporal or permanent location.

Below is a comprehensive list of the HTTP Redirection Status Codes, their reasons, and usage notes.

1. Status Code 300 - Multiple Choices

The 300 status code indicates that the resource requested by the client has multiple representations, for instance, a multi-lingual resource.

The entity-body will contain all the multiple representations of the resource. The format of the entity-body is up to the server to decide; there is no standard definition of how the list of options is to be formatted.

The specification also states that the server could suggest a preferred URI by including it in the response Location header.

2. Status Code 301 - Moved Permanently

The 301 status code Indicates that the representation at the requested location has been moved permanently to another location/URI.

The resource's new location should be specified in the response Location header.

3. Status Code 302 - Found

The 302 status code signals a temporal redirect. It indicates that the representation at the requested location has been moved temporarily.

The new temporal resource location should be specified in the response Location header.

4. Status Code 303 - See Other

The 303 status code informs the client to use a different URL for the request as specified in the response Location header.

5. Status Code 304 - Not Modified

The 304 status code informs the client to use the previous representation of the resource within its cache because the resource has not changed since it was last accessed based on the cache control headers provided by the client.

The 304 status code is an essential status code and, if implemented by a server, can reduce the amount of bandwidth consumed and improves network speed.

6. Status Code 305 - Use Proxy

The 305 HTTP status code indicates that the requested resource must be accessed through a proxy.

The response Location header contains the Proxy URL to be used.

7. Status Code 307 - Temporary Redirect

The 307 status code indicates that the representation or resource at the requested location has been moved temporarily.

The new temporal location of the resource should be specified in the response Location header.

8. Status Code 308 - Permanent Redirect

The 308 status code indicates that the representation or resource at the requested location has been moved permanently.

The new permanent location of the resource should be specified in the response Location header.

Client Error Status Codes - 4xx

Sometimes, Client requests can be erroneous, such as invalid entity-body, no or invalid authorization headers, authentication headers, etc. The 4xx response codes indicate errors in the client request.

Clients can also request a non-existing resource, hence, the famous 404 error response code.

Client Error HTTP status codes are in the range of 400-499, both inclusive. 4xx response codes tell the connected client about the error in the request.

Below is a comprehensive list of the HTTP Error Response Status Codes, their reasons, and usage guides.

1. Status Code 400 - Bad Request

The 400 status code informs the client that it has sent a malformed or bad request. The request entity-body is missing some expected data, or the data provided failed validation.

2. Status Code 401 - Unauthorized

401 status code indicates that the client is not authorized to make the request. It simply means that the server failed to authenticate the client; hence, it could not identify the client.

The 401 status code is returned with appropriate headers that ask the client to authenticate itself.

3. Status Code 402 - Payment Required

402 status code indicates that payment is required before the requested resource can be accessed. At the time of publication, this status code is not used yet.

4. Status Code 403 - Forbidden

The 403 forbidden status code indicates the client does not have permission to perform the requested operation on the target resource.

For security reasons, most servers conceal the reason for forbidding the client but instead include a very generic reason in the response body.

5. Status Code 404 - Not Found

The 404 status code indicates the resource requested at the given location could not be found. Together with the 200 and 500 status codes, the 404 status code is the most popular status code on the internet today.

6. Status Code 405 - Method Not Allowed

The 405 status code Indicates the request method used is not allowed on the specified resource. For instance, it would be appropriate to return a 405 status code when a client issues a POST request on a resource that allows only a GET or HEAD request.

7. Status Code 406 - Not Acceptable

Servers issue the 406 status code if the content generated by the requested resource does not match any of the entries in the Client's Accept header.

8. Status Code 407 - Proxy Authentication Required

The 407 status code is used by proxies to indicate that Authentication is required. It is similar to the 401 status code but used by proxy agents.

9. Status Code 408 - Request Timeout

The 408 status code Indicates that the client did not produce a request within the time that the server was prepared to wait.

10. Status Code 411 - Length Required

The 411 status code Indicates that the client must provide a Content-Length header such as during a post and put requests.

11. Status Code 413 - Entity Too Large

The 413 status code indicates that the server refuses to process a request because the request payload is too large.

As part of efforts to prevent DOS attacks, Servers are usually configured to handle a specific max length request payload to prevent DOS attacks.

12. Status Code 414 - Request-URI Too Long

The 414 status code indicates that the server refuses to process the request because the request URL is too large.

This could happen when the client transforms what should be a POST or PUT request into a GET request, making the URI query sections too long.

13. Status Code 415 - Unsupported Media Type

The 415 status code indicates the server refused to process the request because the content type of the request payload is not supported.

14. Status Code 416 - Requested Range Not Satiable

The 416 status code indicates that the range request cannot be satisfied because of out-of-range values specified in the request headers.

15. Status Code 417 - Expectation Failed

The 417 status code indicates the expectation given in an Expect request-header field could not be met.

Server Error Status Codes - 5xx

Aside from client request errors, servers can encounter errors while processing client requests. The 5xx HTTP status codes indicate server-side errors while processing a client request.

Server errors can range from system failure, network errors, code or script errors, gateway errors, etc. Troubleshooting such errors by server administrators usually involves looking up server error log files.

Server Error status codes are status codes in the 500-599 range, both inclusive. 5xx response status codes tell the connected client about the server's error while processing the request.

Please find a comprehensive list of all the Server Error Status Codes, their reasons, and usage notes below.

1. Status Code 500 - Internal Server Error

The 500 status code indicates the server encountered an internal error while processing the request, such as code errors.

2. Status Code 501 - Not Implemented

The 501 status code is sent when a client makes a valid request, but that is beyond the server's capabilities. An example is sending a request using a method not implemented by the server.

3. Status Code 502 - Bad Gateway

The 502 status code indicates that one of the connected servers acting as a proxy could not connect to the upstream server.

4. Status Code 503 - Service Unavailable

The 503 status code indicates that the server cannot service the request at present but will be able to in the future. This can be due to ongoing system maintenance.

5. Status Code 504 - Gateway Timeout

A proxy server sends the 504 status code to indicate that a response from an upstream server is taking too long and exceeds the wait threshold of the proxy server.

6. Status Code 505 - HTTP Version Not Supported

The HTTP 505 status code Indicates that the server does not support the HTTP version used for the request..