Skip to main content
Be Bitwise

HTTP & the Web

Computer Networking Basics · Networking & Cryptography track

5 min read

In this module

The Application Layer

At the top of the networking stack sit the protocols that applications actually speak. The big one for everyday computing is HTTP (HyperText Transfer Protocol) — the language your browser uses to talk to web servers.

Request and Response

HTTP follows a simple pattern. The client (your browser) sends a request, and the server sends back a response. Each request includes:

  • A method that describes the action: GET (retrieve), POST (submit), PUT (replace), PATCH (modify part), DELETE (remove).
  • A URL that identifies the resource.
  • Headers with metadata like the content type and authentication tokens.

The response includes a status code, headers, and usually a body containing the requested data. The first digit gives the family: 2xx success (200 OK), 3xx redirection (301, 304), 4xx a problem with the request (404 not found, 403 forbidden) and 5xx a failure on the server (500).

HTTP itself is stateless: each request stands alone. Sites remember who you are with cookies, small values the server sets in a Set-Cookie header that the browser sends back with every later request to that site, typically carrying a session ID.

HTTP Methods

By convention, most web APIs map methods onto basic operations: GET reads data, POST creates data, PUT replaces a whole resource, PATCH updates part of one, and DELETE removes it. That's a convention rather than a rule of the protocol: POST in particular is the general "process this" method and gets used for all sorts of actions.

Worked Example: One Request, Byte by Byte

HTTP/1.1 is plain text, so you can read it directly. Run curl -v http://example.com/ and curl prints what it sends (lines starting >) and what comes back (<). Stripped of those markers, the request looks like this:

c
GET / HTTP/1.1
Host: example.com
User-Agent: curl/8.5.0
Accept: */*

Line one is the request line: method, path and protocol version, separated by single spaces. Next come the headers, one Name: value per line. Host is compulsory in HTTP/1.1 because one IP address often serves hundreds of sites, and the server needs to know which one you meant. Every line ends in a carriage return and line feed (\r\n), and an empty line marks the end of the headers. A GET has no body, so that blank line is the end of the request.

The response has the same shape:

c
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 1256
<!doctype html>
<html>...

The status line gives the version, the code and a human-readable reason. Content-Length tells the client exactly how many bytes of body follow the blank line, which is how it knows where this response ends and the next one on the same connection begins. (The length here is illustrative; the real page changes from time to time.)

The explorer below runs four requests against a made-up notes API. Flick between them and compare the first line of each response: the status code tells you what happened before you read a byte of body. Check each Content-Length too; it counts the body's bytes exactly.

A small notes API

Read note 7. No body in the request, so it ends at the blank line.

Request
GET /notes/7 HTTP/1.1
Host: api.example.com
Accept: application/json

Response
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 26

{"id":7,"text":"Buy milk"}

Safe and Idempotent Methods

The HTTP specification (RFC 9110) sorts methods by what repeating them does. A safe method is meant to be read-only: GET, HEAD, OPTIONS and TRACE. An idempotent method has the same effect whether you send it once or five times: every safe method, plus PUT and DELETE. POST and PATCH are neither.

MethodSafeIdempotent
GET, HEADYesYes
PUT, DELETENoYes
POST, PATCHNoNo
Predict: your connection drops just after you send a request, and you can't tell whether the server got it. Is it safe to send it again if it was PUT /orders/42 setting the quantity to 3? What if it was POST /orders?

The PUT is fine to repeat. Setting the quantity to 3 twice leaves it at 3, which is exactly what idempotent means. The POST isn't: if the first one did arrive, sending it again may create a second order. That's why browsers ask before resubmitting a form after you hit refresh, and why RFC 9110 says a client shouldn't automatically retry a non-idempotent request unless it has some way to know the retry is harmless. You'll meet this again when replayable requests turn into a security problem.

How a Web Page Loads

Type a URL and press Enter. What looks like a single action is actually a pileup of separate operations:

  1. DNS lookup - the browser resolves the domain name to an IP address.
  2. TCP handshake - a reliable connection is established with the server.
  3. TLS handshake - if HTTPS, encryption is negotiated (more on this in the security module).
  4. HTTP GET request - the browser asks for the HTML document.
  5. Response - the server returns the HTML.
  6. Parsing and follow-up requests - the browser reads the HTML and discovers it needs CSS, JavaScript, images, and fonts. Each triggers another HTTP request.

A single page load can fire off dozens or even hundreds of HTTP requests, parallelised wherever the browser can manage it. HTTP/1.1 needs a separate TCP connection for each request in flight, so browsers open several per site; HTTP/2 multiplexes many requests over one connection, and HTTP/3 does the same over QUIC.

From Signals to Screens

Step back for a second. Loading a web page runs through every layer you've met in this module: electrical signals carrying bits through cables, IP routing packets across continents, TCP making sure nothing evaporates, HTTP structuring the conversation between browser and server. Every layer is doing its job, and you mostly never notice.

Carry that stack in your head and you've got the mental model to debug network weirdness, design APIs that work with the underlying protocols rather than against them, and appreciate why something as mundane as clicking a link involves so many moving parts.