Skip to content

guimarais/fastapi_tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Tutorial - From Zero to Hero

A progressive tutorial for learning FastAPI, where each example builds upon the previous one.

Prerequisites

  • Python 3.11 or higher
  • Basic understanding of Python
  • Familiarity with REST APIs (helpful but not required)

Setup

This project uses uv as the package manager.

Install uv

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Initialize the Project

# Create a new directory
mkdir fastapi-tutorial
cd fastapi-tutorial

# Initialize with uv
uv init

# Add FastAPI and uvicorn
uv add fastapi uvicorn[standard]

Run Examples

Each example can be run with:

uv run uvicorn example_XX:app --reload

Then visit http://localhost:8000 in your browser.

Tutorial Structure

Part 1: Basics

  • Example 01: Hello World - Your first FastAPI application
  • Example 02: Path Parameters - Dynamic routes
  • Example 03: Query Parameters - URL parameters

Part 2: Request Handling

  • Example 04: Request Body - Handling POST requests with Pydantic
  • Example 05: Response Models - Structured responses
  • Example 06: Status Codes - HTTP status codes

Part 3: Advanced Features

  • Example 07: Path Operations - Multiple HTTP methods
  • Example 08: Dependencies - Dependency injection
  • Example 09: Error Handling - Custom exception handlers

Part 4: Real-World Application

  • Example 10: Complete CRUD API - A todo list application

Learning Path

Follow the examples in order. Each example includes:

  • Python code file (example_XX.py)
  • Explanation document (example_XX.md)
  • Key concepts demonstrated
  • What's new compared to the previous example

Documentation

FastAPI automatically generates interactive API documentation:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Resources

About

Small tutorial for FastAPI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published