[{"id":"fastapibeginner-001","courseId":"fastapi-beginner","domain":"routing","topic":"Relative imports for routers","prompt":"A teammate asks how `from .routers import items, users` in app/main.py finds its modules. Put the stages of that lookup in the order the FastAPI guide describes.","hint":"Think about what a leading dot is measured from, and how the containers nest inside one another.","explain":"A leading dot is measured from a place in the project's directory tree, not from a file name. Containers nest inside one another, and a name can only be read from a container the lookup has reached.","source":"https://fastapi.tiangolo.com/tutorial/bigger-applications/","interaction":{"type":"sort","items":[{"text":"Start in the package that holds app/main.py","why":"The leading dot begins the lookup in the package containing the module that writes the import."},{"text":"Look for the routers subpackage at app/routers/","why":"routers is a subpackage of that package, so it must be located before anything inside it can be reached."},{"text":"Import the items submodule from routers","why":"items is a submodule file taken from routers, so its router variable becomes available as items.router."},{"text":"Import the users submodule the same way","why":"The guide repeats this for users after items, and importing the submodules keeps the two router variables from colliding."}]},"options":[],"answer":"o:abcd","explanation":"A relative import is resolved in stages: the leading dot anchors the lookup in the package holding the importing file, the routers subpackage is found inside it, and each listed submodule is then imported from there so its router variable stays separate.","concept":"A relative import is resolved in stages: the leading dot anchors the lookup in the package holding the importing file, the routers subpackage is found inside it, and each listed submodule is then imported from there so its router variable stays separate.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Import router submodules by name when several of them share the variable name router."]},{"id":"fastapibeginner-002","courseId":"fastapi-beginner","domain":"routing","topic":"Path parameters","prompt":"A client calls GET /items/abc on this route. What does FastAPI do?","hint":"Look closely at the type annotation on item_id.","explain":"A type hint on a path parameter does more than document it: the URL text is converted to that type and checked against it. Consider what the framework reports when a value cannot be converted.","source":"https://fastapi.tiangolo.com/tutorial/path-params/","interaction":{"type":"single"},"options":[{"id":"a","text":"An HTTP error response whose detail reports int_parsing for the path parameter item_id","why":"A value that cannot be parsed as an int is rejected with a detail list that names item_id as the location and int_parsing as the type."},{"id":"b","text":"Passes the string 'abc' to read_item unchanged","whyNot":"The page shows the value being converted to the annotated type, as 3 becomes a Python int rather than the string '3'."},{"id":"c","text":"Returns a 404 Not Found because no item has that id","whyNot":"The page's failure is about the value's type, shown as int_parsing; it is not a missing-item result."},{"id":"d","text":"Converts 'abc' to 0 and returns item_id as 0","whyNot":"The page's example rejects 'foo', which is not an int, rather than substituting a value such as 0."}],"answer":"a","explanation":"Path parameters are parsed and validated using their type hints. A value that cannot be parsed to the annotated type gets an error response whose detail names the parameter and a type such as int_parsing.","concept":"Path parameters are parsed and validated using their type hints. A value that cannot be parsed to the annotated type gets an error response whose detail names the parameter and a type such as int_parsing.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"@app.get(\"/items/{item_id}\")\nasync def read_item(item_id: int):\n    return {\"item_id\": item_id}","takeaways":["A type hint on a path parameter is enforced, and a value that fails it is reported in the error detail."]},{"id":"fastapibeginner-003","courseId":"fastapi-beginner","domain":"routing","topic":"Query parameters","prompt":"A teammate writes this route. Which TWO statements about skip and limit are correct?","hint":"Think about which part of the URL carries these values, and what a default changes.","explain":"Arguments that match no placeholder in the path form a separate kind of input. A declaration can say more about such an input than its type, and that extra detail changes what a client must do.","source":"https://fastapi.tiangolo.com/tutorial/query-params/","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"A client can send skip and limit after the ? in the URL, as key=value pairs joined by &","why":"Parameters not named in the path are read from the query string: the key=value pairs that follow the question mark."},{"id":"b","text":"A request that leaves out limit still works, because the parameter has a default value","why":"A parameter with a default is optional; FastAPI uses the default when the client does not send it."},{"id":"c","text":"Both values must be placed in the path, such as /items/0/10, because they are path parameters","whyNot":"Only names written in braces in the path are path parameters; these two are not in the path, so they are query parameters."},{"id":"d","text":"They are read from a JSON request body, so a GET request must send one for them to work","whyNot":"Query parameters come from the URL, not from a body."},{"id":"e","text":"A request with limit=abc still succeeds, since query values are never converted","whyNot":"Query values are converted to the annotated type, so a value that is not an integer is rejected."},{"id":"f","text":"Both must always be sent, because an int parameter has no default unless Optional is used","whyNot":"Being an int does not make a parameter required; a default value is what makes it optional."}],"answer":"ab","explanation":"Parameters not named in the path are query parameters, read from the part of the URL after the ?. A default value makes a query parameter optional, not its type.","concept":"Parameters not named in the path are query parameters, read from the part of the URL after the ?. A default value makes a query parameter optional, not its type.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"fake_items_db = [{\"item_name\": \"Foo\"}]\n\n@app.get(\"/items/\")\nasync def read_items(\n    skip: int = 0, limit: int = 10\n):\n    return fake_items_db[skip:skip + limit]","takeaways":["A default value is what makes a query parameter optional; the type annotation alone does not."]},{"id":"fastapibeginner-004","courseId":"fastapi-beginner","domain":"routing","topic":"Route declaration order","prompt":"In FastAPI, if the route for /users/{user_id} is declared above the route for /users/me, a request to /users/me still reaches the /users/me function.","hint":"Think about how a request is matched against a list of paths.","explain":"Path operations are checked against each request in turn. A placeholder in braces accepts any value in its spot, so the shape of each route decides which requests it can catch.","source":"https://fastapi.tiangolo.com/tutorial/path-params/#order-matters","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The earlier {user_id} route also matches /users/me, with user_id set to 'me', so it handles the request and the later route is never reached."},{"id":"b","text":"False","why":"Paths are matched in declaration order, so the first route that fits, here /users/{user_id}, wins."}],"answer":"b","explanation":"Path operations are matched in the order they are declared, and the first path that fits a request handles it. Put fixed paths before parameterized ones they could be caught by.","concept":"Path operations are matched in the order they are declared, and the first path that fits a request handles it. Put fixed paths before parameterized ones they could be caught by.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"@app.get(\"/users/{user_id}\")\nasync def read_user(user_id: str):\n    return {\"user_id\": user_id}\n\n@app.get(\"/users/me\")\nasync def read_me():\n    return {\"user\": \"current\"}","takeaways":["Declare fixed paths like /users/me before parameterized ones like /users/{user_id}."]},{"id":"fastapibeginner-005","courseId":"fastapi-beginner","domain":"routing","topic":"Header parameters","prompt":"A handler declares a parameter named user_agent with a Header() marker. Which request header does FastAPI read for it?","hint":"Look at how FastAPI maps a Python parameter name to a header name.","explain":"HTTP header names often contain hyphens, which Python identifiers cannot. FastAPI bridges that gap when it looks up a header for a parameter, so you name the parameter in Python style.","source":"https://fastapi.tiangolo.com/tutorial/header-params/","interaction":{"type":"single"},"options":[{"id":"a","text":"User-Agent","why":"FastAPI converts the underscores in the parameter name to hyphens, so user_agent reads the User-Agent header."},{"id":"b","text":"user_agent","whyNot":"Underscores are not kept in the header name; FastAPI converts them, so this exact name is not used."},{"id":"c","text":"X-User-Agent","whyNot":"FastAPI adds no prefix to header names; it only converts underscores to hyphens."},{"id":"d","text":"Agent","whyNot":"The whole parameter name is converted, not just its last word."}],"answer":"a","explanation":"Header parameters are declared like query, path and cookie parameters. FastAPI converts underscores in the parameter name to hyphens, so user_agent reads the User-Agent header.","concept":"Header parameters are declared like query, path and cookie parameters. FastAPI converts underscores in the parameter name to hyphens, so user_agent reads the User-Agent header.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"@app.get(\"/items/\")\nasync def read_items(\n    user_agent: Annotated[\n        str | None, Header()\n    ] = None,\n):\n    return {\"user_agent\": user_agent}","takeaways":["Name header parameters in Python style; FastAPI looks up the hyphenated header name."]}]