FastAPI - Dependency Injection
Which of the following code snippets correctly uses a shared dependency in FastAPI?
Dependency functions should be passed as callable to Depends() without calling them.
async def get_db(): pass
@app.get('/items')
async def read_items(db=Depends(get_db)): pass correctly passes get_db as callable. Options B and C call the function directly, and D passes Depends without callable.
15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions