FastAPI - Dependency Injection
Given this code, what will be the response when calling GET /items/42?
from fastapi import FastAPI, Depends
app = FastAPI()
class ItemDependency:
async def __call__(self, item_id: int):
return f"Item ID is {item_id}"
@app.get('/items/{item_id}')
async def read_item(dep: str = Depends(ItemDependency())):
return {"message": dep}