FastAPI Project Setup and First Endpoint
Install FastAPI, create a project, and write your first GET endpoint.
What Is FastAPI?
FastAPI is a modern Python web framework for building REST APIs. It provides automatic OpenAPI docs, type-checked request/response models via Pydantic, and async-native performance.
# pip install fastapi uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def root():
return {"message": "Hello, FastAPI"}Running the Server
Run with uvicorn. The --reload flag restarts automatically on code changes during development.
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/health")
def health(): return {"status": "ok"}
# Terminal:
# uvicorn main:app --reload
# → http://127.0.0.1:8000
# → http://127.0.0.1:8000/docs (Swagger UI)All lessons in this course
- FastAPI Project Setup and First Endpoint
- Path Parameters, Query Params, and Request Bodies
- Dependency Injection and Authentication
- Async Endpoints and Database Integration