
- Set up project structure and FastAPI app - Create database models and SQLAlchemy connection - Implement Alembic migration scripts - Add CRUD API endpoints for Todo items - Add health check endpoint - Set up validation, error handling, and middleware - Add comprehensive documentation in README.md
23 lines
718 B
Python
23 lines
718 B
Python
import time
|
|
from typing import Callable
|
|
|
|
from fastapi import FastAPI, Request, Response
|
|
|
|
|
|
def add_logging_middleware(app: FastAPI) -> None:
|
|
"""
|
|
Add middleware for request logging.
|
|
"""
|
|
@app.middleware("http")
|
|
async def log_requests(request: Request, call_next: Callable) -> Response:
|
|
start_time = time.time()
|
|
|
|
response = await call_next(request)
|
|
|
|
process_time = time.time() - start_time
|
|
response.headers["X-Process-Time"] = str(process_time)
|
|
|
|
# Log request details (in a real app, use a proper logger)
|
|
print(f"{request.method} {request.url.path} - {response.status_code} - {process_time:.4f}s")
|
|
|
|
return response |