fastapi-middleware-toolkit¶
Reusable FastAPI middleware: CORS, error handlers, cache control, lifespan, health checks.
Installation¶
pip install fastapi-middleware-toolkit
Public API¶
Function/Class |
Purpose |
|---|---|
|
CORS with secure defaults |
|
Global error handlers |
|
Default Cache-Control headers |
|
Register cache control |
|
Lifespan context manager |
|
Health check factory |
Usage¶
from fastapi import FastAPI
from fastapi_middleware_toolkit import (
setup_cors_middleware,
setup_error_handlers,
create_lifespan_manager,
)
lifespan = create_lifespan_manager(service_name="api")
app = FastAPI(lifespan=lifespan)
setup_cors_middleware(app, ["http://localhost:3000"])
setup_error_handlers(app)