Top 30 API Interview Questions and Answers
30 multiple-choice questions on API, drawn from 30 bites out of the 114 tagged API on Tezvyn. Answer them here or read straight down. Every question carries the correct option, why it is correct, and a link to the bite it came from.
30 questions. Pick an answer, or open “Show the answer” to read it.
Answers are graded in your browser. Nothing is saved, and no XP or streak is earned here. The app keeps score.
Question 1 of 30
What is the primary reason for creating a single FastAPI instance (e.g., app = FastAPI()) for your application?
Show the answer
Answer: d · It serves as the central manager for all routing, configuration, and lifecycle events.
The FastAPI instance acts as the central, authoritative object that orchestrates the entire application, managing all routing, configuration, and lifecycle events. While it does contribute to API documentation, that is a feature derived from its central management role, not its primary purpose for being a single instance.
Read the full bite: FastAPI Application Instance: Your API's Central Hub
Question 2 of 30
Which scenario represents an inappropriate use of a FastAPI path operation decorator's arguments?
Show the answer
Answer: c · Dynamically changing the HTTP status code based on specific input conditions.
FastAPI decorator arguments are designed for static configuration, such as setting a default status code or grouping endpoints. Dynamic logic, like returning different status codes based on request input, should be handled within the endpoint function itself, not via decorator arguments.
Read the full bite: FastAPI: Configure Endpoints with Decorators
Question 3 of 30
In FastAPI, what is the primary consequence of defining a path parameter without a type hint (e.g., item_id instead of item_id: int)?
Show the answer
Answer: c · The path parameter will always be treated as a string, regardless of its content.
The card explicitly states that 'without int, 123 is just a string,' meaning FastAPI treats untyped path parameters as strings by default. FastAPI does not infer types for path parameters; it requires explicit type hints for validation and conversion.
Read the full bite: Path Parameters: Turning URL Parts into Variables
Question 4 of 30
For which purpose are FastAPI query parameters most appropriately used?
Show the answer
Answer: b · To provide optional criteria for filtering or paginating a list of items.
The card states query parameters are for optional data like filtering, pagination, or sorting a collection of resources. Options A and D describe the purpose of path parameters, while option A describes when to use a request body, not query parameters.
Read the full bite: FastAPI Query Parameters: Beyond the URL Path
Question 5 of 30
When developing a FastAPI application, for which purpose is a Pydantic BaseModel most effectively utilized?
Show the answer
Answer: d · To define the expected structure and types of data within a POST or PUT request's body.
The card states that Pydantic models are used for 'the request body of any POST, PUT, or PATCH endpoint where the client sends structured data.' Options A, B, and D describe scenarios where Pydantic models are explicitly advised not to be used for the primary request body model, as those are handled by other FastAPI mechanisms like path parameters, query parameters, or Form().
Read the full bite: FastAPI: Pydantic for Robust Request Bodies
Question 6 of 30
When an internal object has fields not defined in a FastAPI response_model, what is the primary action FastAPI takes?
Show the answer
Answer: b · It automatically filters out those extra fields before sending the response.
The `response_model` acts as a stencil, automatically filtering out any fields from the internal object that are not defined in the model before sending the response. It does not raise an error for extra fields, nor does it require manual exclusion for this purpose.
Read the full bite: FastAPI Response Models: Shape Your API's Output
Question 7 of 30
What is the fundamental principle behind FastAPI's ability to provide accurate and up-to-date API documentation?
Show the answer
Answer: d · It automatically generates documentation by introspecting the application's Python code and type hints.
The card states, "Think of your code as the single source of truth for your documentation. FastAPI reads your Python functions, their parameters, their type hints..." This means the documentation is generated directly from the code, ensuring it's always current. Other options describe alternative or supplementary methods, but not FastAPI's core mechanism for documentation generation.
Question 8 of 30
For which scenario is Platform.select the most appropriate tool in React Native?
Show the answer
Answer: a · Adjusting minor UI properties like padding or background color based on the operating system.
Platform.select is designed for small-to-medium platform differences, such as tweaking styles like padding or background colors. It is explicitly advised against for entire screens or complex logic flows, which are better handled by platform-specific file extensions.
Read the full bite: Platform.select: Write Once, Adapt Anywhere
Question 9 of 30
A library updates from version 1.2.3 to 2.0.0. What does this change primarily signal to users?
Show the answer
Answer: b · Existing code using the library might break and require modifications.
A MAJOR version increment (from 1.x.x to 2.0.0) signals incompatible API changes, meaning existing code relying on the previous API may break. New backward-compatible features are MINOR changes, and bug fixes are PATCH changes.
Read the full bite: Semantic Versioning: A Contract for Your Code's Evolution
Question 10 of 30
When a parameter validated by FastAPI's Query or Path objects fails its defined constraints, what is the immediate outcome?
Show the answer
Answer: b · FastAPI stops request processing and returns a 422 Unprocessable Entity error to the client.
The card states that if validation fails, FastAPI immediately stops processing and returns a 422 Unprocessable Entity error. This prevents invalid data from reaching your function and provides clear feedback to the client, unlike the other options which describe different error handling or value manipulation.
Read the full bite: FastAPI: Validate Parameters with Query and Path
Question 11 of 30
What is a critical behavior of Dimensions.get('window') that developers must account for?
Show the answer
Answer: c · Its returned value is a static snapshot that does not update automatically on dimension changes.
The card explicitly states that Dimensions.get() takes a 'single photograph' of the screen's size and 'won't update on rotation,' meaning its value is static at the time of the call. Option D describes the behavior of the useWindowDimensions hook, which is designed for automatic updates and re-renders in functional components.
Read the full bite: React Native's Dimensions API: The Manual Approach
Question 12 of 30
Which is the correct way to set a 201 Created status for a new resource created via a FastAPI POST endpoint?
Show the answer
Answer: c · @app.post("/items/", status_code=201)
The card explicitly states that the success status code should be set in the path operation decorator, as shown in option C, because it's part of the endpoint's contract. Option A is identified as a 'common footgun' for placing it in the function signature, and option D incorrectly uses HTTPException for a success code.
Read the full bite: FastAPI: Set a Response's HTTP Status Code
Question 13 of 30
In a FastAPI application, when is it appropriate to explicitly raise HTTPException?
Show the answer
Answer: b · To signal that a requested resource or business rule violation occurred due to client input.
HTTPException is designed for expected, client-caused errors like a missing resource (404) or a permission issue (403), which stem from business logic. FastAPI automatically handles Pydantic validation errors (422) and it's not for unexpected server bugs (500).
Read the full bite: FastAPI: Use HTTPException to Return Client Errors
Question 14 of 30
What happens if an application uses the OpenTelemetry API but does not configure an SDK?
Show the answer
Answer: d · The API calls will execute as "no-op" operations, effectively generating no telemetry.
The card explicitly states that "By default, if no SDK is configured, these calls do nothing; they are 'no-op'". This means no telemetry data is generated or buffered, and a default SDK is not automatically activated.
Read the full bite: OpenTelemetry API: The Stable Interface for Your Code
Question 15 of 30
What is the primary benefit of defining a model signature for an ML model?
Show the answer
Answer: c · It programmatically enforces the expected data contract, preventing runtime errors from invalid inputs.
The card explicitly states that model signatures were created to "enforce this contract programmatically, preventing bad data from ever reaching the model and ensuring reliability" and to prevent "runtime errors from mismatched data shapes, missing columns, or wrong data types." Other options describe related but distinct aspects of ML model management, not the core function of a signature.
Read the full bite: Model Signature: The API Contract for Your ML Model
Question 16 of 30
A developer aims to create a real-time, collaborative design editing experience using the Figma REST API. Why is this approach fundamentally flawed?
Show the answer
Answer: c · The API is primarily designed for static data extraction and automation, not live, synchronous updates.
The Figma REST API is an asynchronous request-response system designed for data extraction and automation, not for mirroring the live, multiplayer experience of the Figma app. While parsing large JSON might be a performance consideration, the API's fundamental design as an asynchronous system is the core limitation for real-time collaboration, not the data complexity itself.
Read the full bite: Figma REST API: Access Design Files as Structured Data
Question 17 of 30
When consuming a REST API, what is the primary function of the HTTP status code in the server's response?
Show the answer
Answer: a · To inform the client about the outcome of its request, such as success or failure.
The card explains that the HTTP status code is "the waiter telling you if your order succeeded," directly indicating its role in communicating the success or failure of the request. Other options describe functions handled by HTTP headers or the URL.
Read the full bite: Consuming REST APIs: Speaking to Web Services
Question 18 of 30
A Python daemon runs nightly without user interaction to pull API data on its own behalf. Which OAuth 2.0 approach should it use to obtain an access token?
Show the answer
Answer: b · Use the client credentials grant, authenticating directly to the token endpoint with its client_id and client_secret.
A daemon acting on its own behalf should use the client credentials grant and authenticate directly to the token endpoint with its client_id and client_secret. The authorization code flow with a stored refresh token is designed for scripts acting on behalf of a user, not for non-interactive service-to-service calls.
Read the full bite: Implement OAuth 2.0 flow to get an access token for API requests
Question 19 of 30
What is the primary reason JSON is widely adopted for data exchange in web APIs?
Show the answer
Answer: b · It provides a human-readable, text-based format for structured data that is easily parsed by various programming languages.
JSON's main advantage is its simple, text-based, and human-readable structure, which allows different systems and programming languages to easily exchange and parse structured data. It is not a binary format, nor does it execute code, and it explicitly lacks support for comments.
Question 20 of 30
Which scenario best illustrates the appropriate use case for OAuth 2.0 authentication compared to a simple API key?
Show the answer
Answer: a · A mobile application requesting access to a user's social media profile on a third-party platform.
OAuth 2.0 is designed for delegated authorization, allowing third-party applications to access a user's resources with their consent, without sharing the user's credentials. Simple API keys are better suited for trusted server-to-server communication or basic access control where user consent and granular permissions are not required.
Question 21 of 30
When returning data from a JSON API, why is res.json preferred over res.end for sending an object?
Show the answer
Answer: d · res.json serializes the object and sets application/json, while res.end does neither
res.json stringifies the object and sets the JSON content type; res.end sends raw data with no serialization or content-type help. res.end is not deprecated, and res.json does serialize rather than skip it.
Question 22 of 30
Which scenario is least suitable for declaring individual HTTP headers using Header() in a FastAPI path operation?
Show the answer
Answer: a · Handling a full OAuth2 authentication and authorization flow.
The card explicitly advises against using Header() for complex authentication schemes like OAuth2, as FastAPI provides dedicated security utilities for such cases. It is well-suited for simpler tasks like reading User-Agent, API keys, or tracing IDs.
Question 23 of 30
Which statement best describes a key advantage of GraphQL for client applications over traditional REST APIs?
Show the answer
Answer: d · It allows clients to specify exact data fields from multiple related resources in one network call.
The card emphasizes that GraphQL allows clients to ask for exactly the data they need in a single call, solving over-fetching and under-fetching issues. Distractor C is incorrect because the card explicitly states that caching is more complex with GraphQL, requiring sophisticated strategies.
Read the full bite: GraphQL Queries: Ask for Exactly What You Need
Question 24 of 30
What is the primary function of declaring a parameter with Cookie() in a FastAPI path operation?
Show the answer
Answer: b · To retrieve the value of a specific cookie sent by the client in the request.
The card states that `Cookie()` is used to signal to FastAPI that a parameter's value should come from a request cookie, allowing it to extract the value. Option D is incorrect because the card explicitly warns against using `Cookie()` to send cookies back to the client.
Question 25 of 30
Which scenario best illustrates the primary benefit of using a webhook?
Show the answer
Answer: a · A payment gateway automatically notifying an e-commerce platform upon successful transaction completion.
The primary benefit of webhooks is enabling real-time, event-driven communication by having a service notify your application when an event occurs, avoiding inefficient polling. Option A exemplifies this by showing a payment gateway proactively notifying an e-commerce platform, whereas other options describe polling, synchronous requests, or batch processing.
Question 26 of 30
What is the main reason to use the WHATWG URL API instead of manual string manipulation for handling URLs?
Show the answer
Answer: b · It provides a structured object to safely parse, access, and modify URL components.
The WHATWG URL API's primary benefit is converting a raw URL string into a structured object, allowing safe and predictable access and modification of its components, thereby preventing common parsing errors and security vulnerabilities. It does not validate resource existence, encrypt data, or shorten URLs for performance.
Read the full bite: WHATWG URL API: Safely Parse URLs, Not Strings
Question 27 of 30
What is a key benefit of using gRPC for internal microservice communication compared to REST/JSON?
Show the answer
Answer: a · It enforces a strict, language-agnostic contract, leading to higher performance and fewer integration issues.
The card highlights that gRPC enforces a strict contract via Protocol Buffers, which prevents data mismatch errors and, combined with efficient binary transport, leads to high performance. Options A and D describe attributes that are either benefits of REST/JSON or scenarios where gRPC is not recommended.
Read the full bite: gRPC: High-Performance RPC with Contracts
Question 28 of 30
In FastAPI, when you need to add a custom HTTP header like a trace ID to a JSON response without altering the response body, what is the correct method?
Show the answer
Answer: b · Declare a Response parameter in the path operation, set headers on its .headers attribute, and return your data normally.
The card states to declare a Response parameter, set headers on its .headers attribute, and then return your data normally. Returning the Response object directly (option A) is explicitly warned against as a 'footgun' because FastAPI automatically merges the headers with your returned data.
Read the full bite: FastAPI: Setting Custom Response Headers
Question 29 of 30
For what primary purpose should a developer use FastAPI's Depends feature in an API endpoint?
Show the answer
Answer: c · To manage shared setup tasks, such as database connections or user authentication.
The card states that Depends solves "repeated setup and teardown code" and is used for "managing database connections" and "handling security." It delegates prerequisite tasks, not the main business logic, response formatting, or error handling.
Read the full bite: FastAPI's Depends: Let the Framework Handle Setup
Question 30 of 30
What is the primary benefit of using a class as a dependency in FastAPI?
Show the answer
Answer: b · To group logically related request parameters for reuse across multiple endpoints.
The card emphasizes that class dependencies are used to bundle related request parameters, like for pagination, to avoid duplication and improve code structure across multiple endpoints. Options A and C describe the use of Pydantic models for data validation and serialization, which is a different FastAPI feature, while option A refers to authentication, another distinct use case for dependencies.
Could you explain these out loud?
That is what an interview actually tests. Tezvyn gives you questions like these with what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.