The internet carries billions of websites across the globe. If you, being an ordinary user wanted to check the score of your favorite team, check your bank account, browse emails, book flights, or research for a college project, a specific website address is needed to pull the desired information. Whenever a Uniform Resource Locator (URL) is entered in the browser (client), a request is sent to the server (where the website is being hosted). Put differently, the client submits a Hypertext Transfer Protocol (HTTP) request to the server, which returns a response or an HTTP status code to the client on whether that particular request has been successful or not. You make the request using the HTTP protocol, and the server responds.
In this context, a protocol is a digital language with mutually acknowledged rules that allow communications to be both sent and read across the internet. There are several protocols available with varying attributes such as DNS, FTP, HTTP, IRC, and SSL. In this article, we will focus on the HTTP protocol status codes. Whenever a request is sent to the server, the status code relates the condition of the request as to whether it is a success, failure, or in-between. Although these statuses are returned each time the client interacts with the server, it is unnecessary for the end-user to repeatedly see these transactions. However, HTTP status codes are crucial for developers and testers to diagnose and fix problems in the configuration of the websites.
How do HTTP Status Codes work?
Whenever a user enters an URL into the browser, a request is sent to the web server, which then processes and sends back a response. This response is often received in the form of HTML, CSS, PDF, or JSON as a whole bunch of documents along with an HTTP header. The HTTP header carries information about the client, server, and the requested page, and they also contain the status codes. These codes are returned each time a server receives a request from the client and again, it is not necessary for the user to view these codes but they do appear when something goes wrong.
There are many tools such as Web Sniffer available for testers and developers to view the HTTP status codes that normally, we cannot see on browser.
Categories of HTTP Status Codes
There are five categories of status codes where the first digit of every code indicates the category in which it belongs. For example, the 404 status code belongs to the category of 4xx. The classification of categories is described below:
- 1xx: This is an informational category and indicates that the request from the client has been initiated by the server.
- 2xx: When a request received by the server from the client has been successfully processed or completed, then a success message is displayed.
- 3xx: There are instances when a web page or some information which a user requested may have been moved to another page or a link, so a redirection takes place. This means that the server received the request, but further action is needed to enable completion of that particular request.
- 4xx: This category is classified as client error codes. The request has been received by the server but it cannot proceed because it may contain incorrect syntax.
- 5xx: This category implies server error. This status code appears when the request is valid but it contains an error so the the server is unable to fulfill the request.
List of Important Status Codes
There are above 40 status codes and here, we will discuss few of them.
Informational 1xx:
- 100 Continue: This indicates that a partial request is received from the client and as long as the request is not rejected, the client should continue with it.
- 102 Processing: This error code implies that the request from the client has been received and the server is processing the particular request, but the status of that request will be returned later. This status code is similar to “100 Continue” where the result might be returned immediately, whereas in “102 Processing” the result will be returned after the full request has been received.
Successful 2xx:
- 200 OK: When the request by the server is successful and it works as expected then this status code generates. Usually, these are not visible to the user.
- 201 Accepted: This status indicates that the request from the client has been accepted for processing but the process has not yet completed successfully.
Redirection 3xx:
- 301 Moved Permanently: This status code depicts that the page requested by the client is not available on the given address and is moved permanently. The user is navigated to that new address in an unnoticed manner.
- 302 Found: This status code is often misunderstood. This status implies that the resource which the client is trying to access has been moved to a different URL temporarily. In other words, the content is hosted somewhere else for the time being.
- 303 See Other: This status indicates that the result requested by the client can be found in a different location. When a client tries to get a response against a POST request, the server responds with a success message. Instead of showing the message from the server, a good practice is to redirect the user to a particular URL.
Client Error 4xx:
- 400 Bad Request: This code converys that the request received by the client to the server is not understood and requires modification while resubmitting the same request. Each status code that starts with its series with 4 indicates that the client did something wrong. 400 is a generic error code and is used in situations where other codes do not fit.
- 401 Unauthorized: This status code indicates that the request made by the client is password protected and requires credentials, such as a username and password, to access. If incorrect credentials were provided, this error code will still be generated.
- 403 Forbidden: This status code implies that the page requested by the client is inaccessible. For example, trying to access such information without providing the correct password may generate this status code from the server.
- 404 Not Found: This widely seen status code means that the content requested by the client does not exist or is not available on the server.
- 408 Request Timeout: This means that request from the client is taking more time than expected to reach the server. The reasons are many such as slow internet connection or no-internet connection.
Server Error 5xx:
- 500 Internal Server Error: Each status code that starts a series with 5 indicates that the server did something wrong. This error occurs on the server side when the request from the client is not retrieved. The reason maybe due to disconnecting from the network, breaking a database connection, or perhaps there’s an error in the code.
- 503 Service Unavailable: This status code indicates that due to the overloaded server the request sent by the client cannot be handled at the moment.
- 504 Gateway Timeout: This error code indicates that the server is acting as a gateway or a proxy, and did not actually receive the desired response on time.
The above mentioned status codes are the important ones which users are likely to find from time to time on a website.
A Note for Testers and Developers
For a better website user experience, it is preferable to keep the appearance of error pages to a minimum. Those websites which have a large audience and frequently changing information, especially online stores and news portals, should work on keeping the automatically generated status codes to a minimum. It is important for businesses to retain their users and a 404 (Not Found) status code will force the user to switch to the competitor’s website.