DEVPREP CODEX · #08
FastAPI Interview Questions
150 curated questions graded from Foundations (Easy) to Practical Patterns (Medium) and Internals & Architecture (Hard).
TOTAL QUESTIONS
150
THEORY QUESTIONS
150
IMPLEMENTATION FOLIOS
0
FREE QUESTIONS
5 / Level
Easy Level·50 Questions Total
Foundations & Core Concepts
Q1What is FastAPI and what makes it popular?
- A modern Python framework for building APIs on standard type hints (ASGI-based, via Starlette + Pydantic).
- Headline features: automatic validation from annotations, interactive docs (Swagger/ReDoc) generated free, async-first performance, dependency injection system.
- Popularity drivers: near-Node throughput with Python ergonomics, minimal boilerplate, editor autocompletion because everything is typed.
Q2What role do type hints play in FastAPI?
- They ARE the framework contract: parameters annotated
int,UUID, Pydantic models drive parsing, validation, serialization and the OpenAPI schema. - Wrong types yield automatic 422 responses with precise error locations — no manual checking code.
- Editors autocomplete everything; mypy catches mismatches pre-runtime. Interview line: "In FastAPI you don't validate inputs; you DECLARE them."
Q3What is a path operation? Show a basic example.
@app.get("/items/{item_id}")
async def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}
- Decorator binds HTTP method + path to function (
@app.get/post/put/delete). - Path parameter typed int → auto-conversion/validation.
- Optional query param
qdefaults None; return dict auto-serialized to JSON.
Q4How do query parameters work?
- Function params not in path become query params:
def list(skip: int = 0, limit: int = Query(default=10, le=100)). - Constraints via
Query(gt=0, max_length=...); alias support maps external names to pythonic ones. - Multiple values:
tags: list[str] = Query([])accepts?tags=a&tags=b.
Q5How do request bodies work with Pydantic models?
class ItemIn(BaseModel):
name: str
price: float = Field(gt=0)
tags: set[str] = set()
@app.post("/items")
async def create(item: ItemIn): ...
- POST/PUT body parsed into the model automatically; nested models validated recursively.
- Extra fields forbidden/configurable (
model_config = ConfigDict(extra="forbid")). - Response model (
response_model=ItemOut) filters output shape separately from input.
45 More Easy Questions Locked
Unlock the complete FastAPI Easy question bank
Get instant access to all 50 questions, in-depth model answers, code sandboxes, and all 27+ technologies for a single one-time payment.
Unlock All — One-time payment · Lifetime access
Browse All FastAPI Questions by Difficulty
Easy50 Questions
Core concepts, definitions, basic syntax, and first principles expected in round 1 screening.
VIEW FULL LIST
Medium50 Questions
Real-world mechanisms, state management, edge cases, performance trade-offs, and practical coding.
VIEW FULL LIST
Hard50 Questions
Deep runtime internals, memory models, distributed design, concurrency failure modes, and architectural decisions.
VIEW FULL LIST
INTERNAL LINKING & DEPENDENCIES