Engineering Toolkit, lesson 10
HTTP APIs with FastAPI
How programs talk over HTTP, and a small API that checks its input.
"Setting up a Python project" for environments and pytest. No web experience needed.
Part 1. A request and a response
When a program wants something from another program on a network, such as a model's prediction or a list of experiments, it usually asks over HTTP, the same protocol a browser uses. It sends a request: what to do, to what, and any data. The other program, the server, sends back a response: how it went, and any data.
Here's one exchange, with a small experiment tracker this lesson builds. curl is a command-line tool that makes HTTP requests; -i shows the response's headers too.
$ curl -i localhost:8000/health
HTTP/1.1 200 OK
date: Wed, 04 Nov 2026 09:30:00 GMT
server: uvicorn
content-length: 15
content-type: application/json
{"status":"ok"}
$ curl -i -X POST localhost:8000/runs -H 'Content-Type: application/json' -d '{"name": "baseline", "score": 0.81}'
HTTP/1.1 201 Created
date: Wed, 04 Nov 2026 09:30:00 GMT
server: uvicorn
content-length: 39
content-type: application/json
{"name":"baseline","score":0.81,"id":1}And here's the second exchange as it travelled, in plain text (curl's -v shows this). The request: a method and a path, then headers, a blank line, and a body. The response: a status code, headers, a blank line, and a body. The body is JSON, text that maps straight onto Python dicts, lists, strings and numbers.
POST /runs HTTP/1.1
Host: localhost:8000
User-Agent: curl/8.7.1
Accept: */*
Content-Type: application/json
Content-Length: 35
{"name": "baseline", "score": 0.81}
HTTP/1.1 201 Created
date: Wed, 04 Nov 2026 09:30:00 GMT
server: uvicorn
content-length: 39
content-type: application/json
{"name":"baseline","score":0.81,"id":1}HTTP method
The verb at the start of a request. GET reads, POST creates, PUT replaces, PATCH changes part of something and DELETE removes it.
Your turn
A client's network drops before the answer arrives, so it doesn't know if its request worked. Which request can it safely send again?
JSON
A text format for data: objects in {}, lists in [], strings in double quotes, numbers, true, false and null. Python's json module reads and writes it, and most APIs speak it.
Part 2. Status codes say what happened
Keep going with Pro
You've done the first part. Pro opens the rest of this lesson, and every other one.
- Status codes say what happened
- A small API with FastAPI
- Testing an API without a server
Engineering Toolkit overviewSpotted a mistake? Tell us.