How the web works
URLs, clients and servers, and the steps between typing an address and seeing a page.
The web is a conversation between a client (your browser, an app or a command like curl) and a server. They speak HTTP, the HyperText Transfer Protocol: the client sends a request, the server sends back a response.
Anatomy of a URL
https://www.example.com:443/guides/http?lang=en#headers
\___/ \_____________/ \_/ \___________/ \______/ \_____/
scheme host port path query fragment- scheme: the protocol,
httporhttps. - host: the server name, resolved to an IP address by DNS.
- port: optional, 80 for HTTP and 443 for HTTPS by default.
- path: which resource on the server.
- query: extra parameters after
?. - fragment: a position inside the page after
#. It is handled by the browser and never sent to the server.
What happens when you open a page
- The browser asks DNS for the IP address of the host.
- It opens a connection to that address on port 443.
- For HTTPS, client and server agree on encryption (TLS) and the server proves its identity with a certificate.
- The browser sends an HTTP request.
- The server sends an HTTP response: a status code, headers and usually a body.
- The browser reads the HTML and makes more requests for images, styles and scripts.
HTTP versions
HTTP/1.1 is text-based, one request at a time per connection. HTTP/2 multiplexes many requests over one connection. HTTP/3 runs over QUIC on UDP port 443. The semantics (methods, status codes, headers) are the same in all of them.
See it yourself
curl -v https://example.com # -v shows the connection, TLS handshake, request and response headersTest yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.