Bird
0
0

Which of the following is the correct way to pass a parameter to a dependency in FastAPI?

easy📝 Syntax Q12 of 15
FastAPI - Dependency Injection
Which of the following is the correct way to pass a parameter to a dependency in FastAPI?
ADepends(get_user(user_id=5))
BDepends(get_user, user_id=5)
CDepends(get_user)(user_id=5)
DDepends(get_user)[user_id=5]
Step-by-Step Solution
Solution:
  1. Step 1: Recall Depends usage

    Depends expects a callable or a call to a callable that returns a dependency.
  2. Step 2: Passing parameters

    To pass parameters, you call the dependency function inside Depends, like Depends(get_user(user_id=5)).
  3. Final Answer:

    Depends(get_user(user_id=5)) -> Option A
  4. Quick Check:

    Call dependency inside Depends to pass parameters [OK]
Quick Trick: Call dependency inside Depends() to pass parameters [OK]
Common Mistakes:
MISTAKES
  • Passing parameters directly to Depends without calling
  • Using brackets [] instead of parentheses ()
  • Trying to call Depends as a function with parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes