swadhinbiswas docs: build docs_site — restructure sidebar, create 37 new pages · 7/25/2026
98106de
39 lines · 1.1 KB
Raw Download

title: Dependencies in Path Operation Decorators
description: Declare dependencies directly in the route decorator instead of as function parameters.
keywords: [JustAPI, dependencies, route decorator, dependency injection]

Decorator-Level Dependencies

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.

Useful For

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

See Also