Performance: Basic query parameter declaration
LOW IMPACT
This affects how quickly the server can parse and handle incoming query parameters, impacting response time and user experience.
from fastapi import FastAPI app = FastAPI() @app.get("/items") def read_items(q: str | None = None): # Let FastAPI handle query parameter parsing automatically return {"q": q}
from fastapi import FastAPI app = FastAPI() @app.get("/items") def read_items(q: str = None): # Manually parse query string inside the function # instead of using FastAPI's automatic parsing import urllib.parse query_string = "q=example" params = urllib.parse.parse_qs(query_string) q_value = params.get('q', [None])[0] return {"q": q_value}
| Pattern | CPU Overhead | Code Complexity | Response Time Impact | Verdict |
|---|---|---|---|---|
| Manual query parsing inside endpoint | High (extra parsing) | High (more code) | Increases by ~5-10ms | [X] Bad |
| FastAPI automatic query parameter declaration | Low (built-in) | Low (simple code) | Minimal impact | [OK] Good |