Performance: Protected routes
MEDIUM IMPACT
This affects the server response time and user experience by adding authentication checks before serving protected content.
from fastapi import FastAPI, Depends from fastapi.security import OAuth2PasswordBearer import asyncio app = FastAPI() oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") async def verify_token_async(token: str): await asyncio.sleep(0) # simulate async I/O return "user123" @app.get("/protected") async def protected_route(token: str = Depends(oauth2_scheme)): user = await verify_token_async(token) return {"message": f"Hello {user}"}
from fastapi import FastAPI, Depends from fastapi.security import OAuth2PasswordBearer app = FastAPI() oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") @app.get("/protected") async def protected_route(token: str = Depends(oauth2_scheme)): user = verify_token(token) # synchronous blocking call return {"message": f"Hello {user}"}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous token verification | N/A (server-side) | N/A | N/A | [X] Bad |
| Asynchronous token verification | N/A (server-side) | N/A | N/A | [✓] Good |