FastAPI

FastAPI Practice

Build production-ready APIs with FastAPI through hands-on challenges, one concept at a time.

FastAPI 0.139FastAPI 0.139Python 3.13Python 3.13
Read the FastAPI overview
Module 1

Path Operations & Routing

Learn how FastAPI turns URLs into handlers: typing the values inside the path so conversion and rejection happen before your code runs, ordering fixed paths ahead of parameterized ones, constraining a segment to a fixed set of choices, and capturing a whole nested path in one parameter.

4
About this challenge

This problem covers reading the values that sit inside a web address, so a caller who puts something unexpected there is turned away before any of your code runs.

About this challenge

This problem covers what happens when two addresses could both match the same request, so a page with a fixed name keeps working after a more general pattern is added beside it.

About this challenge

This problem covers limiting part of an address to a known list of choices, so a typo is refused and told what was allowed rather than quietly answering with nothing.

About this challenge

This problem covers laying out the whole set of addresses a file browser needs, so each one reaches the handler it was meant for and none of them quietly swallows another.

Module 2

Query Parameters

Learn how FastAPI reads the values that arrive in the address bar: declaring them so they convert themselves, filling in the ones a caller leaves out, putting limits on what is allowed, collecting a parameter sent more than once, and binding a public name Python cannot spell.

4
About this challenge

This problem covers searching a store's product catalog with filters a caller may leave out, so an omitted filter falls back to a sensible default and a value that makes no sense is refused with a clear reason.

About this challenge

This problem covers checking the search values a caller sends before they are used, so a term that is too short or a page size that is too large is refused rather than obeyed.

About this challenge

This problem covers reading search options a caller may send more than once or spell with a hyphen, so repeating a filter narrows the listing by each value in turn instead of only the last.

About this challenge

This problem covers accepting a full set of search options from a caller, filling in the ones left out, refusing the ones that break a rule, and reporting back exactly which options the search ran with.

Module 3

Request Body and Pydantic Models

Learn how FastAPI reads what a caller sends in the body: describing its shape as a model, giving optional parts sensible defaults, putting a rule on every field, refusing keys the model never declared, and nesting models inside each other so a mistake is reported at the exact place it happened.

4
About this challenge

This problem covers describing the shape of the data a caller may send when adding an item, so the parts they leave out get sensible values and the parts they get wrong are refused by name.

About this challenge

This problem covers putting limits on each value an order carries, so a quantity, a price or a note outside what the business allows is refused before the order is ever placed.

About this challenge

This problem covers describing data that has parts inside parts, an address and a list of parcels within one shipment, so a mistake anywhere is reported at the exact place it happened.

About this challenge

This problem covers taking a booking that arrives split across the address, the query and a nested body, checking every part of it, and turning down anything that does not fit before the trip is even looked up.

Module 4

Response Models and Status Codes

Learn how FastAPI shapes what leaves your API: declaring a response model so internal values never escape, answering each outcome with the code it deserves, tuning how much of a record goes on the wire, and publishing the same contract in the generated description.

4
About this challenge

This problem covers deciding which parts of a stored user are safe to hand back, so passwords and internal notes stay inside the service while callers still get the details they need.

About this challenge

This problem covers answering each request with the code its outcome deserves, so a caller can tell a newly created thing from a plain success and a removal from a thing that was never there.

About this challenge

This problem covers controlling how much of a record goes onto the wire, so a listing reports only what was actually filled in and a summary reports a fixed handful of fields for everything.

About this challenge

This problem covers settling what an accounts API puts on the wire, so a list stays lean, a single account comes back complete, every outcome carries the right code, and the values meant to stay inside never leave.

Module 5 · Coming soon

Form Data, Files & Cookies/Headers

Learn how FastAPI reads everything a request carries besides its JSON body: the fields a browser form submits, uploaded files single and many, the headers a client sends about itself, and the cookies it carries back, with each part declared so the framework converts and refuses it before your code runs.

4

Login Form Fields

easyNo attempts yet

Validated File Upload

easyNo attempts yet

Header And Cookie Inputs

easyNo attempts yet

Document Portal Intake

easyNo attempts yet
Module 6 · Coming soon

Error Handling

Learn how FastAPI reports what went wrong: raising a failure from deep inside a service and having it answered correctly, giving one kind of business failure its own reply in a single place, reshaping the framework's validation report into the service's own, and holding every refusal to one envelope.

4

Domain HTTP Exceptions

easyNo attempts yet

Custom Exception Handler

easy0 / 1 solved

Reshaped Validation Errors

easyNo attempts yet

Payments Error Contract

easyNo attempts yet

About this path

This path builds APIs with FastAPI: path operations and routing, query parameters, request bodies with Pydantic models, and response models and status codes. You should be able to write basic Python, including type hints, before you start. No earlier FastAPI experience is needed. The response module is about controlling exactly what your API returns, from filtered fields to the right status codes.

Frequently asked questions

4

What will I practice in this path?

4 modules: Path Operations & Routing, Query Parameters, Request Body and Pydantic Models and Response Models and Status Codes. More modules are on the way.

How many challenges are there, and how hard are they?

16 challenges, all easy.

What does this path run on?

Challenges run on FastAPI 0.139 and Python 3.13.

Do I need to install anything?

No. Every challenge runs in a browser-based IDE with everything already set up, and your code is graded automatically against a test suite.

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.