The Plain Picture#
Ordering at a restaurant counter follows a fixed pattern that every restaurant understands:
You: "I'd like to order — item: masala dosa. Notes: no onions, I'm paying by card."
Counter: "OK, order accepted. Notes: ready in 10 minutes. Here's your token."
A request always has an action and a thing; a reply always starts with an outcome. Extra notes go on the side.
The Real Names#
HTTP (HyperText Transfer Protocol) is the application-layer protocol (Networking 1: Addresses and Routing Ch 2) of the web. A client (browser, mobile app, another server) sends a request; the server sends back a response. One request, one response.
In HTTP/1.1 these are literally plain text sent over a TCP connection (Networking 2: TCP, UDP and Ports Ch 4).
Under the Hood#
A request#
GET /notes/priya?page=2 HTTP/1.1 ← request line: METHOD PATH VERSION
Host: studybuddy.app ← headers: "Name: value", one per line
Accept: application/json
Authorization: Bearer eyJhbGciOi...
User-Agent: Mozilla/5.0 ...
← one blank line = "headers are over"
(body — empty for this GET)A response#
HTTP/1.1 200 OK ← status line: VERSION STATUS-CODE REASON
Content-Type: application/json
Content-Length: 47
Cache-Control: private, max-age=60
← blank line
{"owner":"priya","title":"Biology","page":2} ← body: exactly 47 bytesHow HTTP finds message boundaries on a TCP stream#
TCP has no message boundaries (Networking 2: TCP, UDP and Ports Ch 4). HTTP/1.1 solves it:
headers end at the first blank line;
the body's length is given by
Content-Length, or the body is sent in pieces withTransfer-Encoding: chunked(each piece prefixed by its size) when the length isn't known in advance — for example when streaming an AI answer word by word.
The Host header lets one server (one IP address) host many websites: the server reads Host to decide which site
you want. It's required in HTTP/1.1.
Try it: curl -v https://example.com prints the exact request (lines starting >) and response headers (lines
starting <).
Check yourself
4 questionsWhat are the three parts of a request line?
Show answerHide answer
Method, path, HTTP version.
How does the receiver know where the headers end?
Show answerHide answer
A blank line.
How does it know where the body ends?
Show answerHide answer
Content-Length, or chunked transfer encoding.
Why does one IP address serving many websites need the Host header?
Show answerHide answer
The server uses Host to know which of its websites the request is for.