Skip to content

Dependencies in Path Operation Decorators

You can declare dependencies in the decorator itself — they won’t appear as function parameters:

from justapi import JustAPIApp, Depends
app = JustAPIApp()
def verify_api_key():
api_key = request.headers.get("X-API-Key")
if api_key != "secret-key":
raise HTTPException(status_code=403)
return True
@app.get("/items/", dependencies=[Depends(verify_api_key)])
def list_items():
return {"items": []}

The verify_api_key runs before list_items, but list_items doesn’t receive the result as a parameter.

  • Authentication checks where the handler doesn’t need the result
  • Logging or rate limiting
  • Cross-cutting concerns that apply to many routes