Performance: Query parameter validation
MEDIUM IMPACT
This affects the server response time and the speed at which the client receives valid data, impacting perceived page load and interaction speed.
from fastapi import FastAPI, Query app = FastAPI() @app.get("/items") def read_items(q: str = Query(..., min_length=3)): return {"q": q}
from fastapi import FastAPI app = FastAPI() @app.get("/items") def read_items(q: str = None): if q is None or len(q) < 3: return {"error": "Query too short"} # process q return {"q": q}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual validation in endpoint code | 0 (server-side only) | 0 | 0 | [!] OK but slower response |
| FastAPI Query parameter validation | 0 (server-side only) | 0 | 0 | [OK] Fast, efficient validation |