Performance: Async HTTP client calls
HIGH IMPACT
This affects how quickly the server can handle multiple HTTP requests without blocking, improving response time and throughput.
import httpx import asyncio from fastapi import FastAPI app = FastAPI() @app.get('/data') async def get_data(): async with httpx.AsyncClient() as client: response1, response2 = await asyncio.gather( client.get('https://api.example.com/one'), client.get('https://api.example.com/two') ) return {'one': response1.json(), 'two': response2.json()}
import requests from fastapi import FastAPI app = FastAPI() @app.get('/data') def get_data(): response1 = requests.get('https://api.example.com/one') response2 = requests.get('https://api.example.com/two') return {'one': response1.json(), 'two': response2.json()}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous HTTP calls (requests) | N/A (server-side) | Blocks event loop | Delays response rendering | [X] Bad |
| Async HTTP calls with httpx.AsyncClient | N/A (server-side) | Non-blocking event loop | Faster response rendering | [OK] Good |