Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.
Start 7-day trial →
⚡
← Courses
›
FastAPI Production
›
Module 1 · FastAPI Basics
›
Dependency injection — FastAPI's killer feature
quiz
5 / 105
🇺🇸
EN
▼
↗
Share
⋯
More
+100 XP
📋
Task
📖
Theory
🤖
AI Help
Task
📝 **Question:** Why use `Depends()` for authentication instead of validating JWT in each route? 💡 Composition + testability + auto-documentation.
🎯 Quiz
Question
📝 **Question:** Why use `Depends()` for authentication instead of validating JWT in each route? 💡 Composition + testability + auto-documentation.
A
Depends() compiles to a C-level fast path at startup, so the JWT verify call ends up roughly 5x faster than the same code written inline in the route
B
It's the only supported way to read the Authorization header — FastAPI's request object strips that header before the route body sees it for security reasons
C
Composable + testable + auto-documented in OpenAPI; the dep is cached per-request so the JWT is decoded once even if multiple routes need the current user
D
FastAPI rejects any path operation that touches auth state without going through Depends() and fails at app startup with a clear validation error
Submit answer
💬 Discussion
Be the first to ask a question or share a tip.
Sign in
to join the discussion. Reading is free.
Loading discussion…