How the Web Actually Works

Follow a request from the browser to the server and back — URLs, HTTP methods, status codes, headers and the client/server split — then write a tiny request router in real Python.

1. The client and the server

The web runs on a simple conversation between two parties:

  • The client — usually a browser — asks for things.
  • The server — a program running somewhere — answers.

The client always starts the conversation. It sends a request; the server does some work (maybe reads a database, runs some logic) and sends back a response. The browser renders the response. That’s it — every page load, every form submit, every app is this loop repeated.

Browser  ──── HTTP request  ───▶  Server ──▶ (database / logic)
         ◀─── HTTP response ────          

2. Anatomy of a request

A request has a few key parts:

  • Method — what you want to do: GET (read), POST (create), PUT/PATCH (update), DELETE (remove).
  • URL / path — what resource: https://learn.gt/courses/42.
  • Headers — metadata: who you are (auth tokens), what formats you accept.
  • Body — data you’re sending (for POST/PUT), usually JSON.

3. Anatomy of a response

The response comes back with:

  • Status code — a 3-digit summary of what happened.
  • Headers — metadata about the response (content type, caching).
  • Body — the actual content (HTML, JSON, an image…).

Status codes you must know

Range Meaning Examples
2xx Success 200 OK, 201 Created
3xx Redirect 301 Moved Permanently, 302 Found
4xx Client did something wrong 400 Bad Request, 401 Unauthorised, 403 Forbidden, 404 Not Found, 405 Method Not Allowed
5xx Server broke 500 Internal Server Error, 503 Unavailable

Reading status codes is a daily backend skill — they tell you who is at fault and what went wrong.

4. The server’s job: routing

When a request arrives, the server looks at the method and path and decides what to do — this is routing. At its simplest, routing is just a function that maps (method, path) to a response. Let’s write one in real Python.

A tiny request router — Python 3
WHAT TO DO
A server's router decides the status code for an incoming request. Implement route(method, path) to return the correct HTTP status code. Rules: - GET "/" -> 200 (home page exists) - GET "/about" -> 200 (about page exists) - GET anything else -> 404 (not found) - any method other than GET -> 405 (method not allowed) (Check the method FIRST: a POST to "/" should be 405, not 200.)
YOUR CODE (edit here, then press Run)
Ctrl/⌘ + Enter
OUTPUT

5. What you learned

You now have the mental model every backend engineer works from: the client/server request–response loop, the methods that express intent, and the status codes that report the outcome. And you wrote the core of what every web framework does under the hood — a router mapping requests to responses.

Next, we look at where the server keeps its data: a real SQL database, which you’ll query live in the next lesson.

🧪 Want to practise this on your own computer? See how to set up your lab →

📝

Knowledge Check

1 of 3

You open a web page. What is the correct order of events?

Report a problem

About: /lessons/backend-how-the-web-works