Performance: Request body declaration
MEDIUM IMPACT
This affects the server's request processing speed and the initial response time perceived by the user.
from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: str price: float @app.post('/items/') async def create_item(item: Item): return item
from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() @app.post('/items/') async def create_item(item: dict): # process item as a plain dict return item
| Pattern | CPU Usage | Validation Efficiency | Response Time Impact | Verdict |
|---|---|---|---|---|
| Plain dict as request body | High (manual checks) | None (manual or missing) | Slower by several ms | [X] Bad |
| Pydantic model declaration | Low (optimized parsing) | Automatic and fast | Faster response, better LCP | [OK] Good |