Ordering by letter
Imagine a shop you can only talk to by letter. Every letter uses the same order form: what you want to do, which item, a few notes on the envelope, and sometimes a parcel inside.
The shop always writes back on a reply slip with a number on top, so you can tell at a glance how it went. One letter, one reply, every time.
That's HTTP. Your browser writes the letters, and websites are the shops.
Requests and responses
HTTP is a requestโresponse protocol. A request has:
| Part | Example |
|---|---|
| Method | GET, POST, PUT, PATCH, DELETE |
| Path | /menu?lang=en |
| Headers | Host, Accept, Authorization, Content-Type |
| Body (optional) | JSON, form data, a file |
The response has a status code, headers and a body. GET is safe (it shouldn't change anything) and,
like PUT and DELETE, idempotent: repeating it has the same effect as doing it once. POST is neither,
which is why browsers warn before resubmitting a form.
The number on the reply slip
You don't need to read the whole reply to know what happened. Look at the first digit of the number:
- 2: all good.
- 3: look somewhere else.
- 4: you asked for something wrong.
- 5: something went wrong at the shop.
Status codes
| Class | Meaning | Common codes |
|---|---|---|
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirection | 301 Moved Permanently, 302 Found, 304 Not Modified |
| 4xx | Client error | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests |
| 5xx | Server error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
401 means "we don't know who you are", while 403 means "we know, and the answer is no". Retrying a 4xx
unchanged is pointless; retrying a 5xx or 429 later, with backoff, often works.
Not asking twice
Some replies come with a note: "this is still good for an hour", plus a small version sticker. You keep a copy in your scrapbook. Until the hour is up, you don't write at all. After that, you just ask "I have version 7, has it changed?", and the shop can answer with a tiny slip instead of the whole catalogue.
HTTP caching
Responses can say how long they may be reused, with Cache-Control: max-age=3600, and identify their version
with an ETag. Within max-age the browser (or a CDN in between) reuses the copy without any request. After
that it revalidates with If-None-Match, and the server can reply 304 Not Modified with no body.
Cache-Control: no-store forbids caching (for personal data), and private keeps a response out of shared
caches like CDNs.
One van, many letters
In the old way, a delivery van carries one letter and waits for the reply before taking the next. To speed up, you'd hire several vans. The newer way uses one van, cuts every letter into small labelled pieces, mixes them together, and puts them back together at the other end.
HTTP/1.1, HTTP/2 and HTTP/3
HTTP/1.1 keeps connections open (keep-alive) but handles one request at a time on each, so browsers open about six connections per host. HTTP/2 multiplexes many requests as interleaved frames on separate streams over a single connection, and compresses headers. HTTP/3 runs the same idea over QUIC on UDP, so one lost packet only delays its own stream instead of everything behind it.
The meaning stays the same in every version: methods, paths, headers and status codes don't change, only how they travel.