# HTTP

HTTP is an Application-layer protocol: it defines how clients and servers exchange web resources, while lower layers deliver those messages across a network.

A useful browser request mental model is:

  1. The browser parses a URL and resolves its host through DNS.
  2. Lower network layers establish a route and connection; TLS protects HTTPS communication.
  3. The browser sends an HTTP request.
  4. A server returns an HTTP response, which the browser parses and renders.

# Client and server

A client starts a request; a browser is the most common web client. A server receives requests and returns resources or generated data. A web server may serve files directly, while an application server runs business logic and often exposes an API.

# Request-response timeline

In the ordinary HTTP request-response model, the client initiates the exchange and the server responds:

Client-server HTTP request-response timeline A client sends an HTTP request to a server, and the server returns an HTTP response. An ordinary HTTP server cannot initiate a request toward the client. Client Server HTTP request HTTP response HTML / CSS / JavaScript server-initiated HTTP request: impossible

The server may return an HTML document that references separate CSS and JavaScript resources, causing the browser to send additional requests. A server cannot start an ordinary HTTP request toward a client that has not requested it; server-initiated updates require another mechanism, such as WebSocket or Server-Sent Events.

HTTP is stateless: each request should contain the information needed to process it. Cookies, authorization tokens, and application data can connect several requests when a stateful user experience is needed.

Continue with:

  1. Network models
  2. Requests and responses
  3. REST APIs
  4. Browser concerns

# Exercise

Open any HTTP-served page (not a file:// URL) in a browser and use DevTools → Network. Identify the document request, its method, URL, status, response headers, and timing.

MDN: An overview of HTTP (opens new window)