Learn HTTP Status Codes

Learn HTTP Status Codes

A tour of HTTP response status codes, what each class means, and when to use which code in your applications.

HTTP Status codes are 3-digit numbers which specify the status of whether a particular HTTP request was completed or not. These codes are a part of header in response.

These codes are not part of site content but rather are a way of informing the client about the status of request sent to server. It is important for any developer to learn about HTTP status codes since proper error codes are super useful in debugging applications. Incorrect HTTP codes lead to confusion, these are set of defined standard codes which are followed all over web.

You probably would have seen 400 Page not found or 500 internal server error while browsing the web. These are some of the HTTP response status codes.

In this article, we will be exploring various types of HTTP status codes and understand when and where to use which code.


Types of HTTP Status Codes

There are five different groups which contain few response status code. The first digit in the 3-digit code represents the class/group of HTTP status code. The five groups are -

  1. Informational responses - 1xx 100199
  2. Successful responses - 2xx 200299
  3. Redirects - 3xx 300399
  4. Client errors - 4xx 400499
  5. Server errors - 5xx 500599

Let's explore each of them in detail -

Informational Responses - 1xx 📘

CodeDescriptionExplanation
100ContinueClient should continue with the request. Some part of the request has been received by the server, but as long as it has not been rejected, .
101Switching ProtocolsClient has asked the server to switch protocols and the server acknowledges with code

Successful responses - 2xx ✔️

CodeDescriptionExplanation
200OKThe request is successful. The response depends on HTTP Methods - GET, POST, etc.
201CreatedNew resource created and successful response.
202AcceptedThe request has been accepted for processing, but the processing has not been completed.
203Non-Authoritative InformationInformation in header is from a local/third-party copy, not from the original server.
204No ContentResponse has status code and header but not body.
205Reset ContentThis response requires that the requester reset the document view.
206Partial ContentServer is returning partial data of the size requested defined by Range header

Redirects - 3xx 👉

CodeDescriptionExplanation
300Multiple ChoicesMore than one possible response. Client chooses one of them.
301Moved PermanentlyThe requested page has moved to a new url. All future request should be made at new url.
302FoundRequested resource resides temporarily under a different url.
303See OtherServer directs the client to get the requested resource at another url.
304Not ModifiedResponse has not been modified, use the cached version.
305Use ProxyRequested resource MUST be accessed through the proxy given by the Location field
307Temporary RedirectClient should continue to use the Request-URI for future requests.

Client errors - 4xx ❌

CodeDescriptionExplanation
400Bad RequestServer could not understand the request due to invalid/malformed syntax.
401UnauthorizedClient should authenticate itself to get the requested response.
402Payment RequiredReserved for future
403ForbiddenClient does not have access rights to the content, even with authentication this request cannot be fulfilled.
404Not FoundServer cannot find the requested page.
405Method Not AllowedHTTP method in request is not allowed.
406Not AcceptableServer is capable of generating only content that is not acceptable by client as specified in header.
407Proxy Authentication RequiredAuthentication is required to be done by a proxy.
408Request TimeoutServer timed out. It did not receive request from client within specific time.
409ConflictThe request could not be completed due to a conflict with the current state of the resource
410GoneRequested page is no longer available. Similar to 404 but this is permanent.
411Length RequiredServer requires Content-Length header.
412Precondition FailedPrecondition given in some request-header fields evaluated to false when it was tested on the server.
413Request Entity Too LargeRequest is too large for server to process.
414Request-URI Too LongQuery string that is too large for the server to process.
415Unsupported Media TypeEntity of the request is in a format not supported by the requested resource.
429Too many requestServer cannot process these many request in given time. (Rate limiting)

Server errors - 5xx 🔻

CodeDescriptionExplanation
500Internal Server ErrorServer has met unexpected condition which has caused an error.
501Not ImplementedServer doesn't support the functionality required to fulfill the request.
502Bad GatewayServer has received an invalid response from the another resource(eg. third party payment request) thus request cannot be fulfilled.
503Service UnavailableServer is overloaded or currently down.
504Gateway TimeoutGateway did not get response in time.
505HTTP Version Not SupportedHTTP version used in the request is not supported by the server.

Resources

You can find browser compatibity data for status code here.

I am working on a side project called Devsheets 🚀 where you can find all cheatsheet for your development. Do Contribute and support!

Liked the article? Consider supporting me ☕️


I hope you learned something new. Feel free to suggest improvements ✔️

I share regular updates and resources on Twitter. Let's connect!

Keep exploring 🔎 Keep learning 🚀

Written by

Mohit Khare

Senior software lead at Abnormal.AI, prev. CRED and Gojek. Backend engineer working on AI, security, and engineering leadership. Based in Bangalore.

Connect on LinkedInMore writing