Performance: Route ordering and priority
MEDIUM IMPACT
This affects how quickly the server matches incoming requests to the correct route, impacting response time and server throughput.
from fastapi import FastAPI app = FastAPI() @app.get("/users/me") async def read_user_me(): return {"user": "current user"} @app.get("/{item_id}") async def read_item(item_id: str): return {"item_id": item_id}
from fastapi import FastAPI app = FastAPI() @app.get("/users/me") async def read_user_me(): return {"user": "current user"} @app.get("/{item_id}") async def read_item(item_id: str): return {"item_id": item_id}
| Pattern | Route Checks | Unnecessary Matches | Response Delay | Verdict |
|---|---|---|---|---|
| Generic route before specific | High (checks all routes until match) | Yes (generic route matches specific paths first, blocking specific routes) | Noticeable delay on specific routes | [X] Bad |
| Specific route before generic | Low (matches specific routes immediately) | None | Minimal delay | [OK] Good |