[{"id":"fastapiadvanced-001","courseId":"fastapi-advanced","domain":"routing","topic":"Custom route class","prompt":"Your API must accept both gzip-compressed and plain JSON bodies on the same route. You must keep the handler's code exactly as it is. Which design handles both?","hint":"Think about where the change should live, before your handler runs.","explain":"A route class can use its own request class, so how incoming data is read can be customized per route. That reading happens before your handler sees the data, so one route can take several formats.","source":"https://fastapi.tiangolo.com/how-to/custom-request-and-route/","interaction":{"type":"single"},"options":[{"id":"a","text":"Subclass Request, override body() to decompress only when the header says gzip, and use a custom APIRoute","why":"The custom request class decompresses the body only when Content-Encoding marks gzip, and the custom route class applies it, so one route takes both kinds."},{"id":"b","text":"Decompress every body inside the route handler, passing plain bodies through","whyNot":"This puts the decompression inside the handler, which the prompt rules out by keeping the handler unchanged."},{"id":"c","text":"Register a second route on the same path that only accepts gzip bodies","whyNot":"The page's point is that one route class handles both compressed and uncompressed requests, so no second route is needed."},{"id":"d","text":"Decompress after the handler has parsed the body, in the response step","whyNot":"The custom reading works on the body before your application processes it, so decompressing afterwards is too late."}],"answer":"a","explanation":"A custom Request subclass can override body() to decompress gzip requests and leave plain ones alone, so one custom route class handles both.","concept":"A custom Request subclass can override body() to decompress gzip requests and leave plain ones alone, so one custom route class handles both.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Custom Request and APIRoute classes are an advanced alternative to middleware for changing how request bodies are read."]},{"id":"fastapiadvanced-002","courseId":"fastapi-advanced","domain":"routing","topic":"Generating clients from OpenAPI","prompt":"You pass a custom generate_unique_id_function to FastAPI to get shorter method names in generated clients. Which TWO statements about that function are correct?","hint":"Look at what the function is handed, and what the schema needs from each ID.","explain":"Each endpoint in a schema needs an identifier, and by default it comes from the function name, path and HTTP method. Changing how it is built changes client method names.","source":"https://fastapi.tiangolo.com/advanced/generate-clients/","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It receives an APIRoute and returns a string","why":"The page says the function takes an APIRoute and outputs a string, which FastAPI uses as the path operation's ID."},{"id":"b","text":"Each ID it returns must still be unique across all path operations","why":"OpenAPI requires operation IDs to be unique across all path operations, so a custom scheme must guarantee that itself."},{"id":"c","text":"It only changes the generated client; the OpenAPI schema keeps the default IDs","whyNot":"The unique ID is used as the operation ID in the schema and for custom model names, so the schema changes too."},{"id":"d","text":"Two path operations may share an ID if they sit under different tags","whyNot":"OpenAPI requires each operation ID to be unique across all path operations, not just within one tag."},{"id":"e","text":"It receives the endpoint's function arguments and returns the response model's name","whyNot":"The function takes an APIRoute, not the endpoint's arguments, and it returns a string used as the ID."},{"id":"f","text":"It is attached with a decorator on each individual path operation","whyNot":"You pass it once to FastAPI as the generate_unique_id_function parameter, which applies to the whole app."}],"answer":"ab","explanation":"FastAPI passes each APIRoute to generate_unique_id_function, which returns a string used as the operation ID; OpenAPI requires operation IDs to be unique across all path operations.","concept":"FastAPI passes each APIRoute to generate_unique_id_function, which returns a string used as the operation ID; OpenAPI requires operation IDs to be unique across all path operations.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Custom operation IDs can shorten generated client method names, but you must keep them unique yourself."]},{"id":"fastapiadvanced-003","courseId":"fastapi-advanced","domain":"routing","topic":"WebSocket endpoints","prompt":"In a WebSocket endpoint, Query and Depends parameters are read differently from HTTP path operations, so you need separate code for each kind.","hint":"Ask whether the way parameters are declared depends on the type of route.","explain":"Declarations tell FastAPI where each value comes from, such as the path, the query string, a cookie or a dependency. Consider whether a WebSocket endpoint needs its own rules for them.","source":"https://fastapi.tiangolo.com/advanced/websockets/","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The page says these parameters work the same way in WebSocket endpoints as in other FastAPI endpoints and path operations."},{"id":"b","text":"False","why":"WebSocket endpoints declare Query, Cookie and Depends the same way as path operations, with no separate rules."}],"answer":"b","explanation":"The WebSockets page says Depends, Security, Cookie, Header, Path and Query work the same way in WebSocket endpoints as in other FastAPI endpoints and path operations.","concept":"The WebSockets page says Depends, Security, Cookie, Header, Path and Query work the same way in WebSocket endpoints as in other FastAPI endpoints and path operations.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["WebSocket endpoints take the same parameter declarations as HTTP path operations, including Depends and Query."]},{"id":"fastapiadvanced-004","courseId":"fastapi-advanced","domain":"routing","topic":"Webhooks in OpenAPI","prompt":"A partner wants to receive your order events by webhook. Using FastAPI's OpenAPI webhook support, what does FastAPI give you?","hint":"Ask who starts the request in this setup, and who writes the sending code.","explain":"Normally a client starts an exchange and the server replies. Here the roles flip. Think about which parts of that outgoing process a framework can describe, and which parts your code must run.","source":"https://fastapi.tiangolo.com/advanced/openapi-webhooks/","interaction":{"type":"single"},"options":[{"id":"a","text":"A documented webhook name, HTTP method and request body in the OpenAPI schema","why":"The page says OpenAPI lets you define the webhook names, HTTP operation types and request bodies your app would send."},{"id":"b","text":"A background task that sends each event to the URL the partner registered","whyNot":"The page says the code that registers URLs and sends the requests is up to you, so FastAPI does not do it."},{"id":"c","text":"A stored list of partner URLs that FastAPI retries when a delivery fails","whyNot":"URL registration and sending are your code's job; the feature only documents what your app would send."},{"id":"d","text":"An incoming route that receives and validates the partner's events","whyNot":"Here your app sends requests out, so the feature covers outgoing requests, not an incoming route."}],"answer":"a","explanation":"The OpenAPI webhooks page says FastAPI lets you define webhook names, HTTP operation types and request bodies, but the logic to register URLs and send the requests is up to you.","concept":"The OpenAPI webhooks page says FastAPI lets you define webhook names, HTTP operation types and request bodies, but the logic to register URLs and send the requests is up to you.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["OpenAPI webhooks document the requests your app may send; they do not register URLs or send anything for you."]},{"id":"fastapiadvanced-005","courseId":"fastapi-advanced","domain":"routing","topic":"OpenAPI callbacks","prompt":"Your invoices API calls a partner's endpoint after each invoice is created, and partners need to see that endpoint's shape. What does FastAPI's callback feature give you?","hint":"Ask who sends the request in this setup, and what the feature is meant for.","explain":"An app may send a request to a service someone else builds, which must answer in a set form. Describing that form helps those builders. Consider whether a description also makes the app send anything.","source":"https://fastapi.tiangolo.com/advanced/openapi-callbacks/","interaction":{"type":"single"},"options":[{"id":"a","text":"Documents the partner endpoint's path, expected body and response in the generated docs","why":"The page says callbacks let you document how the external API should look: its path operation, the body it expects and the response it returns."},{"id":"b","text":"Makes FastAPI send the partner request automatically each time the invoice route runs","whyNot":"The page presents callbacks as documentation of that external API, not as a request FastAPI runs for you."},{"id":"c","text":"Adds a route your app exposes, which the partner calls when an invoice is created","whyNot":"In the callback pattern the partner's software calls your API and your API then calls back; the feature documents the callback side."},{"id":"d","text":"Retries the partner call with backoff when it fails","whyNot":"The feature is about documenting how the external API should look, not about retry behavior."}],"answer":"a","explanation":"OpenAPI callbacks let you document how an external API should look, including its path operation, the body it should expect and the response it should return.","concept":"OpenAPI callbacks let you document how an external API should look, including its path operation, the body it should expect and the response it should return.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Callbacks are a documentation feature: they describe a partner's endpoint in your docs, with its path, body and response."]}]