codejump

Dependencies & API Design

Preview — 3 of 10 questions

Why can /users/me become unreachable here?

javascript
@app.get("/users/{user_id}")
def user(user_id: str):
    return {"id": user_id}

@app.get("/users/me")
def me():
    return {"id": "me"}
AFastAPI forbids two GET routes under /users
BThe earlier dynamic route can match me first
Cme is a reserved Python identifier
DThe static route requires a Pydantic model

What does this declaration enforce for GET /items?limit=0?

javascript
from typing import Annotated
from fastapi import Query

def list_items(limit: Annotated[int, Query(ge=1, le=100)] = 20):
    return limit
AIt silently changes 0 to 1
BIt accepts 0 and returns it
CIt rejects 0 as a validation error
DIt treats 0 as a missing value

Which annotation explicitly marks a nested Pydantic value as a request body?

AAnnotated[Item, Body()]
BAnnotated[Item, Path()]
CAnnotated[Item, Header()]
DAnnotated[Item, Cookie()]

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.