HTTP: requests, responses and statelessness

Unit 1 of 5 in Web fundamentals.

You will be able to read an HTTP request and response and explain what stateless means.

Lesson

A conversation of messages

HTTP is a client-server protocol for fetching resources such as HTML documents. Requests are initiated by the client, usually a web browser. A client and a server communicate by exchanging individual messages rather than a continuous stream.

RFC 9110 describes HTTP as a stateless request and response protocol: a client sends a request message with a method and a request target, and may include header fields. The server answers with a response.

Methods say what the client wants

The method names the action. GET requests a representation of the specified resource; requests using GET should only retrieve data and should not carry a request body. MDN explains that methods can be safe, idempotent or cacheable, which tells caches, browsers and security tools what is safe to repeat or store.

Defenders read the method first, because it shows what the client says it wants to do.

Headers carry the details

Header fields are the labelled details attached to a message, such as what content type is being sent or which cookies the client holds. MDN notes that new header semantics can even be introduced by agreement between a client and a server, so the set of headers keeps growing.

A server's response also carries a status code that says how things went. The curl tool and your browser's developer tools show all of this, and the labs in this unit teach you to read it raw.

Stateless, but not sessionless

HTTP is stateless: there is no link between two requests being successively carried out on the same connection. That is awkward for something like a shopping basket. MDN points out that while the core of HTTP is stateless, cookies allow stateful sessions to be built on top. The next unit covers that, and it is also where many security mistakes live.

Key points

Sources

Practice in the labs

Make requests by hand so a response is never a mystery.

Knowledge check

  1. What does it mean that HTTP is stateless? Answer: There is no link between two successive requests. MDN: there is no link between two requests carried out one after the other on the same connection; RFC 9110 calls it a stateless request/response protocol.
  2. Which method should only retrieve data? Answer: GET. MDN says requests using GET should only retrieve data and should not carry a body.
  3. How do shopping baskets work over a stateless protocol? Answer: Sessions are built on top, typically with cookies. MDN: HTTP is stateless but not sessionless; cookies let sessions be added on top.

Back to the syllabus or see all classes.

Related