Appendix A. The Status Codex
An HTTP status code is a three-digit number attached to an HTTP response. Itâs a bit of protocol semantics that lets the client know, on the most basic level, what happened when the server tried to handle the request. The 41 HTTP response codes defined in the HTTP specification form a set of basic protocol semantics that any API can use.
Apart from HTTP redirects, and the famous â404 Not Foundâ error page
notwithstanding, we donât really use status codes on the World
Wide Web. A human learns what happened to a request by reading the
entity-body served as part of the response, not by looking up a
numeric code in the HTTP standard. When you fill out a form on a
website, but you forget to fill in one of the required fields, the
server sends back an error message, but the response code associated
with the error message is 200 (OK
).
Thatâs fine. You donât even see the response code. You read the error
message and correct the problem. But an API that behaved that way
would be lying to its client! Computer programs are very good at
looking up numeric codes, and very bad at understanding prose. When
you serve the 200 status code on an error condition, you must write
extra documentation explaining that in your API, OK
doesnât
necessarily mean OK. That extra documentation means more work for
your users.
In the world of APIs, then, HTTP response codes become very important. They tell a client how to regard the document in the entity-bodyâwhether ...
Get RESTful Web APIs now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.