Video lecture
Watch on YouTube(opens in a new tab)Sub topic 1
Clients and Servers: The Big Picture
Prerequisites
Assume you know how to use a browser, recognize basic HTML, and run terminal commands. This chapter uses networking terms such as IP address and TCP connection.
Clients and Servers
A client is software that requests a resource. A browser is a client. A server is software that receives requests, performs work, and sends responses. The server may return HTML, JSON, images, or an error.
The exchange usually follows this sequence:
A single page can trigger many exchanges. The browser requests the document first, then discovers and requests stylesheets, scripts, images, and fonts.
Anatomy of a URL
A URL identifies a resource and describes how to reach it.
| Part | Example | Purpose |
|---|---|---|
| Scheme | `https` | Protocol to use |
| Host | `www.example.com` | Server name |
| Port | `:443` | Network endpoint, often implicit |
| Path | `/docs/index.html` | Resource location |
| Query | `?page=2` | Parameters for the request |
| Fragment | `#intro` | Location within the returned document |
For example, https://example.com:443/docs?page=2#intro uses HTTPS, contacts example.com on port 443, requests /docs, and supplies page=2. The fragment normally stays in the browser and is not sent to the server.
Finding and Reaching the Server
DNS, the Domain Name System, maps a hostname to an IP address. The browser can then contact that address. DNS may return several addresses, allowing distribution across servers.
An IP address identifies a network interface. TCP, the Transmission Control Protocol, creates a reliable byte stream between the client and server. A TCP connection uses an IP address and port, such as port 443 for HTTPS.
HTTPS adds TLS encryption after the connection begins. TLS authenticates the server and protects HTTP data from network observers.
HTTP Requests and Responses
HTTP messages contain a start line, headers, a blank line, and sometimes a body.
GET /index.html HTTP/1.1
Host: example.com
Accept: text/html
The server might respond:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 14
<h1>Hello</h1>The method says what the client wants. The status code says what happened. Headers provide metadata, such as the content type or caching rules.
Exercise
Which URL part does DNS resolve, and which part identifies a location inside a document?
Show answer
DNS resolves the host, such as example.com. The fragment, such as #intro, identifies a location inside the document.