HTTP Status Codes
A borrow request fails. Was the book already on loan? Did the member forget to sign in? Did the server crash? A client program cannot read an apology, but it can read a three-digit number. The status code is how BookNook tells a machine what happened, before it reads a single byte of the body.
The rule
The first digit says who: 2 fine, 4 you, 5 me.
Status codes come in families, and the first digit tells you most of what you need:
- 1xx informational: rarely seen in API work.
- 2xx success: the request did what it asked.
- 3xx redirection: look elsewhere, or use your cached copy.
- 4xx client error: the request was wrong; retrying it unchanged will usually fail again. (429 is the exception: wait, then retry.)
- 5xx server error: the server failed; the same request may work later.
The codes you will reach for most:
| Code | Use it when |
|---|---|
200 OK |
A read or update succeeded and returns a body |
201 Created |
A POST created something; add a Location header |
204 No Content |
It worked and there is nothing to return, as after DELETE |
304 Not Modified |
The client's cached copy is still good |
400 Bad Request |
The request is malformed, such as broken JSON |
401 Unauthorized |
No valid credentials: "who are you?" |
403 Forbidden |
Known user, but not allowed: "I know you, and no" |
404 Not Found |
No such resource |
409 Conflict |
Clashes with current state, such as borrowing a book already on loan |
422 Unprocessable Content |
Well-formed, but the values break a rule |
429 Too Many Requests |
The client hit its rate limit |
500 Internal Server Error |
An unexpected bug on the server |
503 Service Unavailable |
Temporarily overloaded or down for maintenance |
The shortcut
Ask three questions in order: Did it work? If not, whose fault? Then, which exact reason?
Did it work?
No loan was created, so not 2xx.
The biggest trap is returning 200 OK with {"error": "book unavailable"} in the body. Every client, monitor and retry library reads the status first, and 200 tells them all it succeeded.
Drills
Answer fast — trust the rule.
A request to BookNook returns 503. Whose side is the problem on?
A POST creates member 88. Which response fits best?
A signed-in member asks to see another member's loan history and is not allowed. Which code?
A new book is sent with "pages": -5. The JSON parses fine. Which code fits best?
Which failed request is worth retrying later without changing it?
Remember
- The first digit says who: 2 fine, 4 you, 5 me.
- Shortcut: did it work, whose fault, which reason.
- Trap: 200 with an error body, and mixing up 401 (who are you?) with 403 (not allowed).
