link
fastapi/dependency

Dependency Injection

Use dependency injection

di
architecture

Command

Examples

Simple dependency

async def common_parameters(q: Optional[str] = None, skip: int = 0, limit: int = 100):
      return {"q": q, "skip": skip, "limit": limit}
  
  @app.get("/items/")
  async def read_items(commons: dict = Depends(common_parameters)):
      return commons