> ## Documentation Index
> Fetch the complete documentation index at: https://fastapi2day.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# FastAPI Foundations: Build Production-Ready Python APIs

> Explore the FastAPI Foundations module — from HTTP basics to JWT auth, covering everything you need to build production-ready Python APIs.

This module is your guided path from zero to a fully working, production-ready FastAPI backend. You'll start by understanding how the web actually works — the HTTP protocol, request-response cycles, and status codes — and then progressively build up to writing authenticated, database-backed REST APIs. Whether you've touched Python before or are brand-new to backend development, this module assumes only a basic familiarity with Python and teaches everything else step by step.

## What You'll Build

Throughout this module, you'll develop an **Employee Management System (EMS)** API — a realistic project that grows with you as you learn. By the end, it handles authentication, database persistence, modular routing, and structured error responses.

```mermaid theme={null}
sequenceDiagram
    actor Client as Client (Browser/App)
    participant Server as Server (FastAPI)

    Client->>Server: HTTP Request (GET /employees)
    Note over Server: Processes request &<br/>fetches employee list
    Server->>Client: HTTP Response (200 OK + JSON Data)
```

## Module Contents

<CardGroup cols={2}>
  <Card title="How the Web Works" icon="globe" href="/fastapi-foundations/how-web-works">
    Understand HTTP, the client-server model, request anatomy, status codes, and REST API conventions.
  </Card>

  <Card title="Intro to FastAPI" icon="bolt" href="/fastapi-foundations/intro-to-fastapi">
    Install FastAPI, write your first application, and run it locally with Uvicorn.
  </Card>

  <Card title="Fundamentals" icon="webhook" href="/fastapi-foundations/fundamentals">
    Learn routing, path/query parameters, request bodies, response models, and the FastAPI architecture.
  </Card>

  <Card title="Request Handling" icon="input-numeric" href="/fastapi-foundations/request-handling">
    Master path parameters, query parameters, request bodies, headers, and the `Annotated` validation style.
  </Card>

  <Card title="Response Handling" icon="upload" href="/fastapi-foundations/response-handling">
    Control outbound data with response models, HTTP status codes, and custom response classes.
  </Card>

  <Card title="Data Validation & Models" icon="shield-check" href="/fastapi-foundations/data-validation-models">
    Separate request, internal, and response models cleanly, and use `Field`, `Query`, and `Path` validators.
  </Card>

  <Card title="Local CRUD" icon="database" href="/fastapi-foundations/local-crud">
    Build a fully functional CRUD API using in-memory dictionaries before adding a real database.
  </Card>

  <Card title="API Documentation" icon="book-open-reader" href="/fastapi-foundations/api-documentation">
    Customise Swagger UI and ReDoc with metadata, route summaries, and field descriptions.
  </Card>

  <Card title="APIRouter" icon="diagram-project" href="/fastapi-foundations/apirouter">
    Split routes into dedicated router files with prefixes, tags, and a clean folder layout.
  </Card>

  <Card title="Exception Handling" icon="bug" href="/fastapi-foundations/exception-handling">
    Handle HTTP exceptions, validation errors, and unexpected runtime errors with global handlers.
  </Card>

  <Card title="Dependency Injection" icon="syringe" href="/fastapi-foundations/dependency-injection">
    Understand IoC and DI principles, then use FastAPI's `Depends()` to inject reusable resources.
  </Card>

  <Card title="Modularisation" icon="folder-tree" href="/fastapi-foundations/modularisation">
    Refactor into a Controller–Service–Repository architecture for scalable, testable applications.
  </Card>

  <Card title="SQL & ORM" icon="database" href="/fastapi-foundations/sql-orm">
    Replace in-memory storage with a real SQL database using SQLModel and SQLAlchemy.
  </Card>

  <Card title="JWT Auth" icon="key" href="/fastapi-foundations/jwt-auth">
    Secure your API with JSON Web Tokens, login endpoints, and role-based access control.
  </Card>
</CardGroup>

## Prerequisites

Before starting, make sure you have the following in place:

* **Python 3.10+** installed on your machine
* A terminal and a code editor (VS Code is recommended)
* Basic Python knowledge — functions, classes, and dictionaries

<Note>
  You do **not** need prior web development experience. Everything from HTTP basics to database integration is covered in this module.
</Note>

## Quick-Start Installation

<Steps>
  <Step title="Create a virtual environment">
    ```bash theme={null}
    python -m venv .venv
    ```
  </Step>

  <Step title="Activate the environment">
    <Tabs>
      <Tab title="macOS / Linux">
        ```bash theme={null}
        source .venv/bin/activate
        ```
      </Tab>

      <Tab title="Windows">
        ```bash theme={null}
        .venv\Scripts\activate
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Install FastAPI and Uvicorn">
    ```bash theme={null}
    pip install fastapi "uvicorn[standard]"
    ```
  </Step>

  <Step title="Create main.py and run it">
    ```python theme={null}
    from fastapi import FastAPI

    app = FastAPI()

    @app.get("/")
    def read_root():
        return {"message": "Hello, World!"}
    ```

    ```bash theme={null}
    uvicorn main:app --reload
    ```

    Visit `http://127.0.0.1:8000/docs` to see your first API docs. 🎉
  </Step>
</Steps>

<Tip>
  Use `uv` as a faster alternative to `pip`. Install it with `pip install uv`, then replace `pip install` with `uv pip install` throughout the course.
</Tip>
