HTTP in Depth
Learn the request/response model, methods, status codes, headers and the differences between HTTP versions.
Beginner · about 6 hours · difficulty 2/5
Learn first: How the Internet Moves Data
HTTP is the language your backend speaks with browsers, mobile apps and other services. A request has a method, a path, headers and an optional body. A response has a status code, headers and an optional body. Everything else (REST, GraphQL over HTTP, webhooks) is built on these pieces.
The parts you use every day
- Methods:
GETreads,POSTcreates or triggers,PUTreplaces,PATCHpartially updates,DELETEremoves.GET,PUTandDELETEare meant to be idempotent: repeating them has the same effect as doing them once. - Status codes: 2xx success, 3xx redirection, 4xx the client did something wrong, 5xx the server failed. Learn the common ones: 200, 201, 204, 301, 304, 400, 401, 403, 404, 409, 422, 429, 500, 502, 503.
- Headers: metadata such as
Content-Type,Authorization,Cache-Control,CookieandAccept.
Versions
HTTP/1.1 sends one request at a time per connection. HTTP/2 multiplexes many requests over a single TCP connection with compressed headers. HTTP/3 runs over QUIC (UDP) to avoid head-of-line blocking. As a backend developer you mostly get HTTP/2 and HTTP/3 for free from your proxy or CDN, but you should know they exist.
Pitfalls
- Returning
200 OKwith an error message in the body. Clients, proxies and monitoring rely on status codes. - Using
GETfor actions that change data. Crawlers and prefetchers will trigger them.
You are ready to move on when you can read a raw request and response (for example with curl -v) and explain every line.
Key concepts
- Request and response anatomy
- HTTP methods and idempotency
- Status code families
- Common headers
- Content negotiation
- HTTP/2 and HTTP/3
- curl and browser devtools: Your main tools for inspecting traffic.
Mini project
Without any framework, build a server using only your language's built-in HTTP module that serves a JSON endpoint, a 404 for unknown paths and a 405 for wrong methods. Inspect it with curl -v.
Check yourself
What is the practical difference between a 401 and a 403 response?
Free resources
- MDN HTTP documentation (MDN)
- RFC 9110: HTTP Semantics (IETF)