Understanding different HTTP status codes

Understanding HTTP Status Codes

An HTTP status code is a server response to a browser’s request. When you visit a website, your browser sends a request to the site’s server, and the server then responds to the browser’s request with a three-digit code: the HTTP status code.

The first digit of each three-digit status code begins with one of five numbers, 1 through 5; you may see this expressed as 1xx or 5xx to indicate status codes in that range. Each of those ranges encompasses a different class of server response.

Importance of HTTP Status Codes

HTTP Status codes are a vital part of web development and every web developer needs to learn about them. These status codes represent a discussion between your browser and the server on the internet. They communicate when anything is amiss, when things are touch and go, or when everything is fine between the two. You can diagnose site issues quickly to reduce downtime by understanding status codes and knowing how to use them. Some of these status codes can even be used to make it easier for users and search engines to find your website; a 301 redirect, for instance, notifies users and bots that a page has moved permanently to a new location.

These status codes are also important for SEO (Search Engine Optimization).Search engine bots see HTTP status codes while they’re crawling your site. In some cases, these messages can influence if and how your pages get indexed, as well as how search engines perceive the health of your site.

Types of HTTP Status Codes

The HTTP Status Codes are divided into five types. They are listed below.

  1. Informational Status Codes (1xx)
  2. Successful Status Codes (2xx)
  3. Redirection Status Codes (3xx)
  4. Client Error Status Codes (4xx)
  5. Server Error Status Codes (5xx)

There are an overwhelming number of status codes, but we will learn about the most important ones only!

Informational Status Codes

Informational status codes indicates that the request from the client has been initiated by the server.

Status CodeMeaning
100 ContinueIndicates that the client should continue the request or ignore the response if the request is already finished.
101 Switching ProtocolsIndicates the protocol the server is switching to.
102 ProcessingIndicates that the server has received and is processing the request, but no response is available yet.
103 Early HintsPrimarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response

Successful Status Codes

Successful status codes indicate that the request received by the server from the client has been successfully processed or completed.

Status CodeMeaning
200 OKThe request succeeded. The result meaning of "success" depends on the HTTP method.
201 CreatedThe request succeeded, and a new resource was created as a result
202 AcceptedThe request has been received but not yet acted upon.
203 Non-Authoritative InformationThis response code means the returned metadata is not exactly the same as is available from the origin server, but is collected from a local or a third-party copy
204 No ContentThis response means that there is no content to send for this request, but the headers may be useful.
205 Reset ContentTells the user agent to reset the document which sent this request.

Redirection Status Codes

Redirection status codes indicate that the server recieved the request, but further action is needed to enable the completion of that particular request. This usually happens when a webpage has been moved temporarily or permanently to another address.

Status CodeMeaning
300 Multiple ChoicesThe request has more than one possible response
301 Moved PermanentlyThe URL of the requested resource has been changed permanently. The new URL is given in the response.
302 FoundThis response code means that the URI of requested resource has been changed temporarily.
303 See OtherThe server sent this response to direct the client to get the requested resource at another URI with a GET request.
307 Temporary RedirectThe server sends this response to direct the client to get the requested resource at another URI with same method that was used in the prior request.
308 Permanent RedirectThis means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header.

Client Error Status Codes

Client error status codes indicate that the request has been received by the server but it cannot proceed because it may contain incorrect syntax.

Status CodeMeaning
400 Bad RequestThe server cannot or will not process the request due to something that is perceived to be a client error
401 UnauthorizedThis 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 ForbiddenThis status code implies that the page requested by the client is inaccessible.
404 Not FoundThis status code implies that the requested resource is not available on the server.
408 Request TimeoutThis means that request from the client is taking more time than expected to reach the server.

Server Error Status Codes

Server error status codes indicate when the request is valid but it contains an error so the the server is unable to fulfill the request.

Status CodeMeaning
500 Internal Server ErrorThe server has encountered a situation it does not know how to handle.
501 Not ImplementedThe request method is not supported by the server and cannot be handled.
502 Bad GatewayThis error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.
503 Service UnavailableThis status code indicates that due to the overloaded server the request sent by the client cannot be handled at the moment.
504 Gateway TimeoutThis error code indicates that the server is acting as a gateway or a proxy, and did not actually receive the desired response on time.