Performance: Why structured responses matter
MEDIUM IMPACT
Structured responses impact how quickly clients can parse and render data, affecting interaction speed and perceived responsiveness.
from fastapi import FastAPI from pydantic import BaseModel from typing import List class Item(BaseModel): id: int name: str class ResponseModel(BaseModel): data: List[Item] message: str app = FastAPI() @app.get("/items", response_model=ResponseModel) async def get_items(): return {"data": [{"id": 1, "name": "Item1"}, {"id": 2, "name": "Item2"}], "message": "Success"}
from fastapi import FastAPI app = FastAPI() @app.get("/items") async def get_items(): return {"data": [{"id": 1, "name": "Item1"}, {"id": 2, "name": "Item2"}], "message": "Success"}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unstructured JSON response | N/A | N/A | Higher due to delayed rendering | [X] Bad |
| Structured Pydantic response model | N/A | N/A | Lower due to predictable parsing | [OK] Good |