What an HTTP request and response look like

HTTP messages are plain text. Each has a first line, headers, a blank line and an optional body.

In a food delivery app, tapping Place order shows a spinner, then Order confirmed with an order number. In between, your phone sent one text message to the app's server and received one text message back. You never see either message.

Your phoneClient
First messageHTTP request
Second messageHTTP response
Think first. A browser or app writes the first message for you. Could you write one yourself without it? Write down what you would need to know.
Nothing stops anyone from typing a request by hand. We do this live with nc in the last step of "Send a request yourself".

A message starts with a first line, then headers, then a blank line, then an optional body. Choose a case, then click any line to see what it does.

Request, browser to server
Response, server to browser
Select a line

Click any highlighted part of the request or response.

More detail

Real browsers send more headers than the samples in this lesson. These are common ones.

In requests

User-Agent: Mozilla/5.0 is a free-text description of the client program. Servers use it for statistics and to decide which files to send, and anyone can fake it.

Accept-Encoding: gzip, br says the client can unpack a compressed reply. If the server agrees, the body is sent 60 to 80 percent smaller, and compressing takes processing time on both ends.

Connection: keep-alive asks the server to keep the connection open because more requests are coming. This avoids paying the setup cost again.

Authorization: Bearer eyJhbGciOi... is proof of who you are. The text after Bearer is a token, a long random string that the server issued at login. Anyone who holds it can act as you, so it must only travel over TLS (encrypted connections).

In responses

Cache-Control: max-age=60 gives permission to reuse this answer for 60 seconds without asking again. A reused answer saves a whole round trip.

An HTTP message is plain text, so you can send a real one yourself. Start a small course server, send it requests with curl, and read the messages it prints. A terminal and Python 3.8 or newer are all you need.

Your instructor can also run these in class.

You can now read a request and a response and send one yourself.

Show the commands

These steps are also the setup for the exercises in Group exercises. On macOS, open the Terminal app. On Windows, open PowerShell.