FastAPI - Dependency Injection
How can you modify this class-based dependency to accept a dynamic parameter from the request query?
Choose the correct way to pass
class UserInfo:
def __init__(self, user_id: int):
self.user_id = user_id
def __call__(self):
return f"User ID is {self.user_id}"
@app.get("/user")
async def user(info: str = Depends(UserInfo)):
return {"info": info}Choose the correct way to pass
user_id from query parameters.