TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

All concepts ยท web ยท protocols

HTTP

The request-and-response language of the web. A client sends a method, a path and headers; the server answers with a status code, headers and a body.

12 min4 animations

๐Ÿ–จ๏ธ Cheat sheet

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:

PartExample
MethodGET, POST, PUT, PATCH, DELETE
Path/menu?lang=en
HeadersHost, 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.

Every question gets one answer5 steps
๐Ÿง’You๐ŸชThe shop
Press play and watch it happen!

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

ClassMeaningCommon codes
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirection301 Moved Permanently, 302 Found, 304 Not Modified
4xxClient error400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests
5xxServer error500 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.

Reading the number on the reply5 steps
๐Ÿง’You๐Ÿš๏ธOld address๐ŸฌNew shop
Press play and watch it happen!

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.

Not asking twice for the same thing4 steps
๐Ÿง’You๐Ÿ“’ Your scrapbook๐ŸชThe shop
Press play and watch it happen!

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.

One line, many letters4 steps
๐Ÿง’You๐ŸชThe shop
Press play and watch it happen!

๐Ÿงฉ Quick quiz

Quick quiz! 3 questions about HTTP, told the same way as the story.
  1. What does the shop always send back for every letter?
  2. The reply slip's number starts with 4. What does it mean?
  3. Your copy's hour is up. What do you ask the shop?
Answer every question to check.Passing marks HTTP as done.
Got the hang of HTTP? Mark it as done, and your paths show how far youโ€™ve got.

Saved in this browser.

๐ŸŒ How the web talksStep 2 of 5

โ† Previous on the path๐Ÿ“– DNSNext on the path โ†’๐Ÿ”’ TLS & HTTPS

๐Ÿ›ก๏ธ Signing in safelyStep 1 of 5

Next on the path โ†’๐Ÿฅฉ Hashing vs encryption

๐Ÿ”Œ Designing APIsStep 1 of 5

Next on the path โ†’๐Ÿฌ REST API design

๐Ÿ‘‰ Read next

  • ๐Ÿ›Ž๏ธAmazon API GatewayThe service counter of a big store: it checks each shopper's card, keeps the queue moving and points them on.
  • ๐Ÿ—ž๏ธAmazon CloudFrontA newsstand in every neighbourhood, sending a runner to the print works only when its copy is missing or stale.
  • ๐ŸชฃAmazon S3A huge storage warehouse: hand in labelled boxes, get them back by label, with copies kept in three buildings.
  • ๐ŸšงCORSA careful parent who won't pass a stranger's note the reply unless the office sends a permission slip.
  • ๐ŸฑGraphQLOrdering a custom bento box on one form: tick exactly what you want, and kitchen stations fill each compartment.
  • ๐ŸŽงgRPC and Protocol BuffersWalkie-talkies with a shared codebook of numbered phrases, so messages are tiny and both sides can talk at once.
  • ๐Ÿ”˜IdempotencyPressing a lift button five times still calls one lift: the system remembers each press.
  • ๐ŸŽŸ๏ธJWTA festival wristband with a tamper-proof stamp that any gate can check without phoning the ticket office.
  • ๐ŸŽกLoad balancingA theme-park host sending each family to the ride with the shortest queue, skipping rides that are broken.
  • ๐Ÿ—๏ธOAuth 2.0A hotel desk gives your helper a key card for one room, for an hour, instead of your master key.
  • ๐ŸฌRate limitingA sweet jar refilled with one sweet a minute: grab a few at once, but never beat the refill rate.
  • ๐ŸฌREST API designA well-organised supermarket: clear labels on every aisle, the same few actions anywhere, and a plain receipt.
  • ๐Ÿ”’TLS & HTTPSSwapping postcards for locked boxes, with a notary's stamp proving the shop is really the shop.
  • ๐Ÿ“žWebSocketSwapping letters for a phone call: keep the line open, and either side can talk the moment something happens.