Create FastAPI web server with standard middleware, JWT authentication, and REST API endpoints
Create a FastAPI web server with standard production-ready middleware and authentication.
Add to pyproject.toml:
fastapi>=0.128.0
uvicorn[standard]>=0.40.0
python-jose[cryptography]>=3.5.0
passlib[bcrypt]>=1.7.4
python-multipart>=0.0.22
email-validator>=2.0.0
src/vibe_piper/web/
โโโ __init__.py # Main FastAPI app
โโโ api/
โ โโโ router.py # API router
โ โโโ endpoints/
โ โโโ auth.py # Authentication endpoints
โ โโโ health.py # Health check endpoints
โ โโโ pipelines.py # Feature endpoints
โโโ middleware/
โโโ error_handler.py # Structured error handling
โโโ rate_limit.py # Rate limiting
โโโ request_id.py # Request ID for tracing
src/vibe_piper/web/__init__.py:
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from vibe_piper.web.api.router import api_router
from vibe_piper.web.middleware.error_handler import add_error_handlers
from vibe_piper.web.middleware.rate_limit import RateLimitMiddleware
from vibe_piper.web.middleware.request_id import RequestIDMiddleware
@asynccontextmanager
async def lifespan(app: FastAPI):
yield
def create_app() -> FastAPI:
app = FastAPI(
title="API Name",
version="0.1.0",
docs_url="/docs",
lifespan=lifespan,
)
app.add_middleware(CORSMiddleware, allow_origins=["http://localhost:5173"])
app.add_middleware(GZipMiddleware, minimum_size=1000)
app.add_middleware(RequestIDMiddleware)
app.add_middleware(RateLimitMiddleware)
add_error_handlers(app)
app.include_router(api_router, prefix="/api/v1")
return app
app = create_app()
Use JWT with python-jose:
Create structured error responses:
class ErrorResponse(BaseModel):
error: str
message: str
detail: dict | None
request_id: str | None
Token bucket algorithm:
uv run vibepiper-server --reload
curl http://127.0.0.1:8000/api/v1/health
This section is preserved when the skill is updated. Put human notes, caveats, and exceptions here.