3. Client and Server
1
The picture to keep in your head2
3.1 What exactly are a client and a server?3
3.2 What's a request and a response?4
3.3 What happens when you type a URL and press Enter?5
3.4 What do GET, POST, PUT, PATCH and DELETE mean?6
3.5 What do status codes tell you?7
3.6 What goes in the headers and what goes in the body?8
3.7 What's the difference between TCP and UDP?9
3.8 How does HTTPS keep the conversation private?10
3.9 Why do keep-alive, HTTP/2 and HTTP/3 make things faster?11
3.10 What does "stateless" mean, and why do we want it?12
3.11 How do cookies, sessions and tokens remember who you are?13
Memory card and where the analogy breaks14
Practice: five levels15
Interview questions16
Solutions17
Sources18
Code lab3. Client and Server
3.2 What's a request and a response?
3 min read+10 XP
In the restaurant: One slip, one plate. You write exactly what you want ("table 4, one masala dosa, no onion"), and you get back exactly that, or the waiter comes back and says "sorry, we're out".
In the system: HTTP works as request and response. The client sends one request; the server sends back one response.
REQUEST RESPONSE
GET /books/42 HTTP/1.1 HTTP/1.1 200 OK
Host: shop.example.com Content-Type: application/json
Accept: application/json Content-Length: 61
{"id": "42", "title": "Designing Systems", "price": 499}
- The request says what you want: a method (GET), a path (/books/42), headers and sometimes a body.
- The response says what happened: a status code (200), headers, and usually a body.
The key rule: the client always starts. In plain HTTP, a server can't send you anything you didn't ask for. If the server has news (a new chat message, a price change), you need extra techniques like polling, WebSockets or push notifications (Chapter 21).
Memory code: "One slip, one plate. Nothing is served that wasn't ordered."