Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Requests and responses on the web

After this lesson: I can say what a request and a response are.

40 min lessonNo commands

Your driver is 4 minutes away

A delivery app says your food is 4 minutes away. A minute later it says 3.

The app does not know this by itself. It asks a server, the server answers, and the app shows the answer.

That question and answer happen millions of times a second across the web.

By the end of this lesson

Note

I can say what a request and a response are.

Key words

WordWhat it meansExample
Requesta message that asks a server for something
Responsethe server's answer to a request
Methodthe kind of requestGET
Status codea number that says how the request went404
Headera named detail sent with a request or response
APIa set of addresses a program can send requests to

The cells students fill in are left blank in this preview.

A request asks and a response answers

The app is the client. It sends a request with a method, an address and some headers.

The server sends back a response. It has a status code, some headers and a body.

The body is the data itself, often in a format called JSON. An API is the set of addresses a server answers on.

A URL is an address in parts

PartIn https://api.shop.example/orders/1042?fields=statusWhat it says
SchemehttpsHow to talk: securely
Hostapi.shop.exampleWhich server
Path/orders/1042Which thing on the server
Queryfields=statusExtra choices for this request

The cells students fill in are left blank in this preview.

The method says what you want

GET reads something and changes nothing. POST creates something new, such as an order.

PUT or PATCH changes something that exists. DELETE removes it.

The same path can do different jobs with different methods.

The first digit of a status says most

A code in the 200s means it worked. The 300s mean the thing has moved somewhere else.

The 400s mean the request was wrong: a bad address, a missing login, a missing field.

The 500s mean the server failed while it tried to answer.

Worked example: real responses

RequestStatusWhat it means
GET /orders/1042200 OKHere is the order
POST /orders201 CreatedThe new order was made
GET /orders/9999404 Not FoundNo order has that number
GET /account, not logged in401 UnauthorizedLog in first
POST /orders, no items400 Bad RequestThe request is missing data
GET /orders/1042503 Service UnavailableThe server is down or too busy

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think every error is the server's fault. A 400s code means the request was wrong, so check what you sent. Only a 500s code points at the server.

Headers carry the details

A header is a name and a value on one line. content-type: application/json says the body is JSON.

Requests carry headers too, such as a login token. The tool curl -i prints a response with its headers, as below.

A real response with its headers

Code: bash
$ curl -i https://api.shop.example/orders/1042
HTTP/2 200
content-type: application/json
date: Tue, 20 Oct 2026 09:15:02 GMT
cache-control: no-store

{"id": 1042, "status": "out for delivery", "eta_minutes": 4}

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.