Advertisement

Most developers know 404 means "not found" and 500 means "something broke", but HTTP status codes are a rich, precise language for describing what happened to a request. Using them accurately — as a server, and reading them correctly as a client — makes web systems far easier to build against and to debug.

The codes are organised into families, and knowing the families is most of the battle.

The families

Status codes group into ranges by meaning. The 200s signal success — the request worked. The 300s indicate redirection — the resource is elsewhere. The 400s mean the client made an error, such as a bad request or a missing resource. The 500s mean the server failed while handling an otherwise valid request. Just knowing which family a code belongs to tells you whose problem it is.

That last distinction is especially useful: a 400-range code points at the request, a 500-range code points at the server.

Advertisement

Why precision matters

Returning the right code lets clients respond intelligently without parsing your prose. A "not found" is handled differently from a "you are not allowed", which differs again from "you sent something invalid" or "try again later". Collapsing all failures into a generic error throws away information that a well-chosen code would convey for free.

Good status codes also make debugging faster, because the code alone often localises the problem before you read a single log line.

Using them well

As a server, choose the most specific accurate code for each outcome, distinguishing client mistakes from server failures and success from redirection. As a client, branch on the code family first and handle the meaningful specifics, rather than treating every non-success identically.

Status codes are a shared vocabulary the whole web already speaks. Using them precisely is a small discipline that pays off every time someone — including future you — has to figure out what a response actually meant.