Curiously Chase

HTTP Status Codes

An overview of HTTP Status Codes

A HTTP status code is how a web server, serving content, communicates the status of that content to the client1.

Status codes are grouped in blocks of 100 so that different types of statuses can be easily inferred. There are currently 5 blocks or categories:

  • 1xx (100-199) - informational
  • 2xx (200-299) - successful
  • 3xx (300-399) - redirect
  • 4xx (400-499) - client error, bad request
  • 5xx (500-599) - server error, okay request, server failed

Only some numbers in a block have a industry standard meaning. This is useful for edge and content delivery networks to more accurately debug customer issues.

1xx Responses

An informational response is issued provisionally to let the client know how a request is being processed and that the client needs to wait for a final response.

I don't see these often in the wild.

Common 2xx Responses

A successful response is the "happy path" of the internet. For the most part you want your responses to be in the 2xx category2

200 OK

This is the standard response for when a request is delivered successfully. The majority of status codes are going to be a 200 OK.

Common 3xx Responses

This category defines how a client should redirect a request based on other information sent from the server.

301 Moved Permanently

Common 4xx Responses

This category means that a request was made from the client that was malformed or incorrect.

This doesn't mean the user did something wrong (although that's possible too), it just means that the request as the server received it was not a request the server could process on the user's behalf.

404 Not Found

This is a common response status code that means the client requested a page or asset that the server didn't have.

In my experience, the majority of the time that this happens is due to a typo on the content creator's part or a URL was modified by the user and it wasn't the correct URL.

Less Common

  • 418 - I'm a Teapot - this error code was an April Fool's joke that indicates the server is a teapot and can't brew coffee. It's sometimes used to respond to automated requests. Read more on MDN (thanks Matt3)
  • 451 - Unavailable For Legal Reasons - this is a proposed error for code for when a user requests a resource that can't be served for legal reasons. (thanks Dylan!4)

Common 5xx Responses

This category is all about an error on the server, even if the request from the client was correct.

This could be because of a bug based on a case the developer didn't think about during development, overload on the server or a server it's making requests from or a configuration issue.

502 Bad Gateway

The server is a proxy or gateway to an upstream but the service it's supposed to serve responded with an invalid response.

504 Gateway Timeout

The server is available but was unable to respond.

Footnotes

  1. client can be a browser or another web server. The internet is a collection of servers, often many, stitched together to serve content. A server will often use the status code it receives from another server to determine what status code to send to the client, sometimes modifying it slightly to differentiate between the status the server received and the status the server sent.

  2. Generally you want 2xx responses, but 3xx responses can be useful for "healing" of a broken URL.

  3. Matt Ginty

  4. my good friend Dylan Garcia

Share on Twitter