Skip to main content

Basic Building Monolith API with FastAPI Quiz

No.Training UnitLectureTraining contentQuestionLevelMarkAnswerAnswer Option AAnswer Option BAnswer Option CAnswer Option D
1Unit 1Lec1Selectors & I/OWhat does the selectors module do in Python?Easy1Monitors multiple file descriptors for I/O readinessReads and writes data from socketsMonitors multiple file descriptors for I/O readinessManages application timeoutsCreates new TCP connections
2Unit 1Lec1Event LoopWhat does asyncio.run_coroutine_threadsafe() do?Hard1Submits a coroutine to a running event loop from a different thread and returns a FutureRuns a coroutine synchronously in the current threadCreates a new event loop for each coroutineBlocks the current thread until the coroutine finishesSubmits a coroutine to a running event loop from a different thread and returns a Future
3Unit 1Lec2Threading & GILFor which type of tasks are Python threads still effective despite the GIL?Medium1I/O-bound tasks like network requests and file readingCPU-bound tasks like matrix multiplicationI/O-bound tasks like network requests and file readingBoth CPU-bound and I/O-bound equallyNeither — threads are always inefficient in Python
4Unit 1Lec3HTTP BasicsWhich HTTP method is idempotent AND used for creating resources?Hard1None — POST creates resources but is NOT idempotentPOSTPATCHGETNone — POST creates resources but is NOT idempotent
5Unit 1Lec3FastAPI IntroFastAPI is built on top of which two libraries?Medium1Starlette and PydanticFlask and MarshmallowStarlette and PydanticDjango and DRFTornado and Cerberus
6Unit 2Lec4Path ParametersWhat does Path(..., gt=0) enforce on a path parameter?Medium1The parameter must be an integer greater than 0The parameter is optionalThe parameter must be a stringThe parameter must be an integer greater than 0The parameter must be less than 0
7Unit 2Lec5Request BodyWhat is the preferred way to define a request body in FastAPI?Easy1Using a Pydantic BaseModel classUsing raw dictionariesUsing Body() for each field separatelyUsing a Pydantic BaseModel classUsing JSON.loads() manually
8Unit 2Lec5Field ValidationHow do you add a custom validator to a Pydantic model field?Medium1Use @field_validator decorator with @classmethodOverride init() methodUse a try/except block in the endpointUse @field_validator decorator with @classmethodAdd validation logic in the route handler
9Unit 2Lec6Cookie ParametersWhat does httponly=True do when setting a cookie?Medium1Prevents JavaScript from accessing the cookie (server-side only)Makes the cookie visible only via HTTPSAllows JavaScript to read the cookieEncrypts the cookie valuePrevents JavaScript from accessing the cookie (server-side only)
10Unit 3Lec7asyncpgWhy do we wrap database operations in conn.transaction()?Medium1To ensure data consistency — if any operation fails the entire batch is rolled backTo improve query speedTo ensure data consistency — if any operation fails the entire batch is rolled backTo enable parallel queriesTo compress the data before sending
11Unit 3Lec8SQLAlchemy ORMIn SQLAlchemy 2.0, how do you define a model column with type annotations?Medium1id: Mapped[int] = mapped_column(primary_key=True)Column(Integer, primary_key=True)db.Column(db.Integer)id: Mapped[int] = mapped_column(primary_key=True)id = IntegerField(primary_key=True)
12Unit 4Lec9Dependency InjectionWhat does Depends() do in FastAPI?Easy1Declares a dependency that FastAPI will resolve and inject into the endpoint functionDeclares a dependency that FastAPI will resolve and inject into the endpoint functionCreates a new database tableDefines a URL path parameterSets the response status code
13Unit 4Lec10CRUD OperationsWhat does await session.refresh(user) do after a commit?Hard1Reloads the user object from the database so it reflects DB-generated values (e.g. auto-increment id)Deletes the user from the databaseReverts the last commitCreates a new user with the same dataReloads the user object from the database so it reflects DB-generated values (e.g. auto-increment id)
14Unit 5Lec11JWT HS256What is the difference between HS256 and RS256 JWT algorithms?Medium1HS256 uses a single shared secret for both signing and verifying; RS256 uses a private key to sign and a public key to verifyHS256 uses public/private keys; RS256 uses a shared secretThey are identical but with different speedsHS256 uses a single shared secret for both signing and verifying; RS256 uses a private key to sign and a public key to verifyHS256 is for encryption; RS256 is for signing
15Unit 5Lec12RBACHow does the require_role() dependency factory enforce RBAC?Hard1It extracts user roles from the JWT claims and returns 403 Forbidden if the user lacks the required roleIt checks the user's IP addressIt validates the request body formatIt extracts user roles from the JWT claims and returns 403 Forbidden if the user lacks the required roleIt creates new roles in the database
16Unit 6Lec13Async TestingWhy can't TestClient be used for async endpoint testing?Hard1TestClient runs synchronously — httpx.AsyncClient is needed to properly test async def endpoints within an async event loopIt doesn't support JSON responsesTestClient runs synchronously — httpx.AsyncClient is needed to properly test async def endpoints within an async event loopIt requires a database connectionIt only works with Flask