Guide 4 · Foundations

APIs and JSON

HTTP from both sides: calling APIs and validating what comes back, then building, documenting and hosting an API of your own.

Complete 18 notebooks 18 written

Before this guide: Python from the Start; Files, Paths and Formats; and Object-Oriented Python.

The notebooks

Open in Colab runs a notebook in your browser, and Read shows it on GitHub without running it. Every notebook runs on its own, and the answers to its exercises are in a separate notebook, linked as Solutions.

1What an API IsRequests, responses, methods, parameters and status codes: the vocabulary of every APIOpen in ColabReadSolutions
2Exploring an APIPostman, curl and interactive docs, and reading an API's documentation before writing codeOpen in ColabReadSolutions
3Your First Requestrequests.get, and everything the response object carriesOpen in ColabReadSolutions
4Status Codes200, 404, 429, 500, and what your code should do about eachOpen in ColabReadSolutions
5Query ParametersThe params argument, encoding, and building a URL correctlyOpen in ColabReadSolutions
6JSON in a ResponseParsing, nested structures, and reaching the field you wantOpen in ColabReadSolutions
7Schemas and ValidationJSON Schema, Pydantic, and a clear error when a response changes shapeOpen in ColabReadSolutions
8Headers and Content TypesWhat you sent, what came back, and why it mattersOpen in ColabReadSolutions
9AuthenticationAPI keys, bearer tokens, and never committing eitherOpen in ColabReadSolutions
10PaginationCursors, page numbers, and a loop that terminatesOpen in ColabReadSolutions
11Rate Limits429, backoff, and being a good citizen of someone else's serverOpen in ColabReadSolutions
12Errors and RetriesTimeouts, connection failures, and what is worth retryingOpen in ColabReadSolutions
13Sending DataPOST, PUT, DELETE, and what idempotent means in practiceOpen in ColabReadSolutions
14A Real ClientOne API wrapped in a small, testable module you would reuseOpen in ColabReadSolutions
15Your First API ServerFastAPI, a route, and the documentation it writes for youOpen in ColabReadSolutions
16Validating RequestsPydantic models on the server, and a 422 with a reason for bad inputOpen in ColabReadSolutions
17A Complete APIThe practice API rebuilt in FastAPI, with every method and the status codes a server choosesOpen in ColabReadSolutions
18Hosting an APIFrom Colab to a public URL: a start command, secrets, and a free hostOpen in ColabReadSolutions

Sources

The real-API examples use weather data from Open-Meteo.com, offered under a CC BY 4.0 license and drawn from the ERA5 reanalysis. Generated using Copernicus Climate Change Service information 2026. Everything else these notebooks request comes from a practice API written for this guide.