HTTP status code

The three-digit number at the start of a response, such as 200 or 404, that says how the server handled the request.

In more detail

Read the first digit first: 2xx means it worked, 3xx means look elsewhere or use what you have, 4xx means the request is wrong and repeating it will not help, and 5xx means the server failed and a retry might work. The exact code then refines that family. A wrong status is a real bug, because clients, caches and retry logic act on it.

Examples

grep -c ' 404 ' access.log
curl -f https://example.com/  # fails on 4xx and 5xx
201 Created, 404 Not Found, 422 validation failure, 429 Too Many Requests, 500 server error, 502 Bad Gateway
w.WriteHeader(http.StatusBadRequest)
Go: w.WriteHeader(http.StatusBadRequest); resp.StatusCode
Spring MockMvc: status().isOk() asserts 200
The first digit is the class: 2xx success, 3xx redirection, 4xx client error and 5xx server error. The class tells you who should investigate: a 4xx usually means the request was wrong, a 5xx that the server failed. An HTTP health check can require a particular status, which proves more than an open port.
status=200 type=text cache=no id=abc is a success response with content, caching and correlation headers.
status=~"5.." selects server errors in PromQL.
Codes in the 200s mean success, 300s redirection, 400s a problem with the request (403 refused, 404 not found) and 500s a server error.
The course uses 404 for objects the caller may not have, so existence is not confirmed, 400 for unknown fields, and 429 when a rate limit is hit.
In this course: A contract test fails if a provider changes the status a consumer depends on, such as returning 200 where 201 was promised. Codes in the 200s mean success, the 400s mean the client made a mistake, and the 500s mean the server failed.

Related terms

Taught in

References

Certification courses