Performance: Path operations (GET, POST, PUT, DELETE)
MEDIUM IMPACT
This affects server response time and client perceived latency when interacting with API endpoints.
from fastapi import FastAPI app = FastAPI() @app.get("/items/{item_id}") async def read_item(item_id: int): # Simulate async processing import asyncio await asyncio.sleep(0.1) return {"item_id": item_id} @app.post("/items/") async def create_item(item: dict): # Async and validation handled return item
from fastapi import FastAPI app = FastAPI() @app.get("/items/{item_id}") def read_item(item_id: int): # Simulate heavy processing import time time.sleep(2) return {"item_id": item_id} @app.post("/items/") def create_item(item: dict): # No validation or async handling return item
| Pattern | Server Blocking | Concurrent Requests | Response Time | Verdict |
|---|---|---|---|---|
| Synchronous blocking code | High (blocks event loop) | Low (serial processing) | Slow (seconds delay) | [X] Bad |
| Asynchronous non-blocking code | Low (event loop free) | High (parallel processing) | Fast (milliseconds delay) | [OK] Good |