HTTP status codes are a critical component of the web protocol, providing information about the status of web requests between clients and servers. They are a 3-digit numeric code that is returned by the server as part of the response to a client’s request. There are many HTTP status codes, but they can be grouped into categories based on their first digit. In this article, we will explore the different categories of HTTP status codes and the meaning of each code in those categories.
The 1xx category of status codes indicates that the server has received the request from the client and is continuing to process it. The server may send additional information to the client during this time, such as a progress update or a request for further action.
For example, the 100 status code (Continue) indicates that the server has received the initial part of the request and is ready to receive the remaining part. The 101 status code (Switching Protocols) indicates that the server is switching to a different protocol, such as from HTTP to WebSocket.
The 2xx category of status codes indicates that the client’s request has been successfully received, understood, and accepted by the server. This means that the server has completed the request and is returning the requested information to the client.
For example, the 200 status code (OK) indicates that the request was successful and the server is returning the requested information. The 201 status code (Created) indicates that the request was successful and the server has created a new resource. The 204 status code (No Content) indicates that the request was successful, but there is no information to return.
The 3xx category of status codes indicates that the client’s request cannot be completed as is and that the client must take additional steps to complete the request. This may involve redirecting the client to a different URL, for example.
For example, the 301 status code (Moved Permanently) indicates that the requested resource has been permanently moved to a new URL. The 302 status code (Found) indicates that the requested resource has been temporarily moved to a new URL. The 304 status code (Not Modified) indicates that the requested resource has not been modified since the last request and can be retrieved from the client’s cache.
4xx: Client error
The 4xx category of status codes indicates that the client has made an error in the request and that the server cannot complete the request as is. This may be due to incorrect formatting, authentication issues, or other client-side errors.
For example, the 400 status code (Bad Request) indicates that the client has made an invalid request and the server cannot understand it. The 401 status code (Unauthorized) indicates that the client must provide valid authentication credentials before the server will complete the request. The 404 status code (Not Found) indicates that the requested resource does not exist on the server.
5xx: Server error
The 5xx category of status codes indicates that the server has encountered an error while processing the client’s request. This may be due to an internal server error, a timeout, or other issues that prevent the server from completing the request.
For example, the 500 status code (Internal Server Error) indicates that the server has encountered an error and cannot complete the request. The 502 status code (Bad Gateway) indicates that the server acting as a gateway or proxy received an invalid response from the upstream server. The 503 status code (Service Unavailable) indicates that the server is currently unavailable and cannot handle the request.
Additional status codes
There are also additional status codes that are not included in the above categories. Some of these status codes are widely recognized and used, while others are less common or may be used for specific purposes.
For example, the 418 status code (I’m a teapot) is a joke status code that was created as an April Fool’s Day joke in 1998. It is not part of the HTTP standard, but it has been used in some web development contexts for fun or to add personality to error messages.
Another example is the 429 status code (Too Many Requests), which indicates that the user has sent too many requests in a given amount of time. This status code is often used to prevent abuse or overloading of a server by limiting the number of requests that can be made by a single user.
The 451 status code (Unavailable For Legal Reasons) is used to indicate that the requested resource is unavailable due to legal reasons, such as a court order or government censorship. This status code is relatively new and not widely used, but it can be useful in certain contexts where legal issues may prevent access to certain resources.
Finally, the 511 status code (Network Authentication Required) indicates that the client needs to authenticate itself in order to access the network. This status code is primarily used in enterprise networks or other closed networks where authentication is required for access.
In conclusion, HTTP status codes are a fundamental part of the web protocol and are used to communicate the status of web requests between clients and servers. Understanding the different categories of status codes and the meaning of each code within those categories is critical for web developers who want to build reliable and user-friendly applications. While there are many different status codes, they can be grouped into categories based on their first digit, with each category indicating a different type of response from the server. By using the appropriate status codes and handling them correctly, web developers can ensure that their applications provide a good user experience and operate reliably and efficiently.