← ClaudeAtlas

fastapi-developmentlisted

Build async APIs with FastAPI, including endpoints, dependency injection, validation, and testing. Use when creating REST APIs, web backends, or microservices.
aiskillstore/marketplace · ★ 329 · API & Backend · score 79
Install: claude install-skill aiskillstore/marketplace
# FastAPI Development ## Quick start Create a basic FastAPI application: ```python from fastapi import FastAPI app = FastAPI() @app.get("/") async def read_root(): return {"Hello": "World"} @app.get("/items/{item_id}") async def read_item(item_id: int, q: str | None = None): return {"item_id": item_id, "q": q} ``` Run with: ```bash uv run uvicorn main:app --reload ``` ## Common patterns ### Pydantic models for validation ```python from pydantic import BaseModel from typing import Optional class Item(BaseModel): name: str description: Optional[str] = None price: float tax: Optional[float] = None @app.post("/items/") async def create_item(item: Item): return item ``` ### Dependency injection ```python from typing import Annotated from fastapi import Depends async def common_parameters( q: str | None = None, skip: int = 0, limit: int = 100 ): return {"q": q, "skip": skip, "limit": limit} CommonsDep = Annotated[dict, Depends(common_parameters)] @app.get("/items/") async def read_items(commons: CommonsDep): return commons ``` ### Database dependencies with cleanup ```python async def get_db(): db = connect_to_database() try: yield db finally: db.close() @app.get("/query/") async def query_data(db: Annotated[dict, Depends(get_db)]): return {"data": "query results"} ``` ### Error handling ```python from fastapi import HTTPException @app.get("/items/{item_id}") async def read_item(