FastAPI Course: Build a REST API in Python

APIs with FastAPI is an intermediate-level course of 5 lessons (about 3 h 33 min), with 16 exercises and 15 quiz questions. Prerequisites: Intermediate Python (Functions, Modules, OOP), HTTP and REST APIs. The course needs a full project environment, planned for a later phase of the platform.

  • Python for the web
  • Intermediate
  • 5 lessons
  • 3 h 33 min
  • 16 exercises
  • Full project environment (phase 2)

The course in brief

This course teaches you to design a professional REST API with FastAPI. You declare typed routes, validate inputs with Pydantic, implement a full CRUD with correct HTTP codes, then add a database, API key authentication and automated tests. The exercises practice the logic in plain Python, and the hands-on tasks are done with the real FastAPI.

What you will be able to do

  • Create and run a FastAPI application and use its OpenAPI documentation
  • Declare and validate path parameters, query parameters and JSON bodies with Pydantic
  • Implement a REST CRUD with the right status codes and HTTPException errors
  • Factor out data access and authentication with dependency injection
  • Persist data with SQLModel and test the API with TestClient

Syllabus: 5 lessons

  1. 01

    First Steps with FastAPI

    15 minFree preview
    • Install FastAPI and run an application with the development server
    • Declare routes with the @app.get / @app.post decorators
    • Explore the automatically generated interactive documentation (OpenAPI)

    FastAPI applicationPath operations (routes)OpenAPI documentation

  2. 02

    Path and Query Parameters

    18 min
    • Declare typed path parameters and query parameters with default values
    • Add validation constraints with Annotated, Path and Query
    • Understand the 422 response generated when data is invalid

    Path parametersQuery parametersAutomatic validation

  3. 03

    Request Bodies and Pydantic Models

    20 min
    • Describe a request's JSON body with a Pydantic model and Field constraints
    • Control the response with response_model or the return type, and choose the status code
    • Separate input, storage and output models so that sensitive data is never exposed

    Pydantic modelsRequest bodyResponse model

  4. 04

    Full CRUD, HTTP Errors and Routers

    20 min
    • Implement CRUD operations with the right methods and status codes
    • Signal business errors with HTTPException
    • Split an API into modules with APIRouter

    CRUD operationsHTTPExceptionAPIRouter

  5. 05

    Dependencies, Database and Tests

    20 min
    • Factor out shared code (database session, authentication) with Depends
    • Persist data in SQLite with SQLModel and parameterized queries
    • Test an API with TestClient and override a dependency during tests

    Dependency injectionDatabaseTests with TestClient

Final project

Reservation Management API

Develop the API of a booking service (rooms, time slots, reservations) with FastAPI and SQLModel. The API exposes a CRUD for rooms, creation and cancellation of reservations with time slot conflict checking (409), a paginated and filterable list, API key authentication for write routes and polished OpenAPI documentation. A pytest suite covers the nominal cases and the errors.

Deliverables

  • A repository with the structure app/main.py, app/routers/, app/models.py and tests/
  • A requirements.txt (or pyproject.toml) file and a README explaining installation and startup
  • A suite of at least ten pytest tests using TestClient and an in-memory database
  • A screenshot or export of the /docs documentation

Assessment criteria

  • Routes follow REST semantics and return the right codes (201, 204, 404, 409, 422, 401/403)
  • Inputs and outputs are described by distinct models; no sensitive data is exposed
  • The database session and authentication go through dependencies
  • Reservation conflicts are reliably detected
  • The tests pass and cover errors as much as nominal cases

Frequently asked questions

What are the prerequisites for this FastAPI course?

You should be comfortable with intermediate Python (functions, classes, type annotations) and know the basics of HTTP and REST APIs: methods, status codes, JSON.

FastAPI or Django: which one should I choose?

FastAPI is ideal for lightweight, fast, well-documented APIs, for example to serve a machine learning model. Django provides a complete framework (ORM, admin, templates) for entire web applications. Both are covered in the learning path.

Do I need to know Pydantic?

No, the course introduces Pydantic v2 over the lessons: models, Field constraints, model_dump and response models.

How are the exercises done?

The code exercises reproduce the logic of an API in standard Python and are graded automatically. The hands-on tasks are done with the real FastAPI in an online development environment.

This course, told for your job

Say what you want to be able to do: “APIs with FastAPI” takes its place in your path, with examples from your field. The concepts stay those of the course.

The preview is free, and you can take the courses one at a time without paying. The path only contains lessons from the catalogue.