Instructions for FastAPI Basics
When assisting with FastAPI basic setup:
- •
Installation:
- •Install with Uv add:
uv add fastapi uvicorn. - •For full features:
uv add "fastapi[all]".
- •Install with Uv add:
- •
Creating the App:
- •Import FastAPI:
from fastapi import FastAPI. - •Instantiate:
app = FastAPI().
- •Import FastAPI:
- •
Basic Endpoint:
- •Define a GET route:
@app.get("/") def root(): return {"message": "Hello World"}.
- •Define a GET route:
- •
Running the Server:
- •Use Uvicorn:
uvicorn main:app --reload(assuming file is main.py). - •Access at http://127.0.0.1:8000.
- •Use Uvicorn:
- •
Interactive Docs:
- •Swagger UI at /docs.
- •ReDoc at /redoc.
- •
Best Practices:
- •Use virtual environments (venv or poetry).
- •Structure project with main.py and separate modules.
- •Enable debug mode for development:
app = FastAPI(debug=True).
References
Use the shared references located at: ../_shared/reference.md