Use the Right HTTP Status Codes

HTTP status codes

Every response from a server carries an HTTP status code, this provides clients with the ability to formally identify the status of the response and has other uses, such as identifying a type of error.

I’m currently working with a “RESTful“ (well, advertised as RESTful) API, where the HTTP status codes are all over the place (hence the reason for this blog post).

An API especially should use the correct status codes so that responses to basic requests can be defined by status codes, without the need for any additional data.

The basics

  • 1xx - Hang on
  • 2xx - Sha-ting
  • 3xx - Move away
  • 4xx - That’s your bad
  • 5xx - That’s my bad

OK, so I’m not being totally serious with these. I’m also not going to write them out or copy and paste, as there are 1000s of websites that already have. Just check Wikipedia for the list.

Test your status codes

There are some online tools to check your status codes, httpstatus.io looks good (and ends with .io, so it must be cool).

I’m a tea pot

The Hyper Text Coffee Pot Control Protocol is a nonessential and humorous communications protocol for controlling, monitoring, and diagnosing coffee pots and has the following status code (yes this is real):

  • 418 I’m a teapot (may be short and/or stout)

Time for a coffee.