Explore key trends and predictions about generative AI's impact…
Start QuizExplore the core ideas behind generative AI interviews, including…
Start QuizExplore how generative AI is reshaping essential business operations,…
Start QuizExplore the fundamentals of evaluating generative AI models in…
Start QuizExplore the basics of Generative AI, large language models,…
Start QuizExplore the fundamentals of how generative AI models generate…
Start QuizExplore the key differences between hard and soft voting…
Start QuizChallenge yourself with essential questions about Oracle Cloud Infrastructure's…
Start QuizTest your understanding of the attention mechanism in Natural…
Start QuizTest your knowledge of caching basics, including time-to-live (TTL),…
Start QuizTest your knowledge of HTTP and REST fundamentals, including…
Start QuizTest your understanding of generative artificial intelligence principles with…
Start QuizTest your understanding of the Retrieval-Augmented Generation (RAG) indexing…
Start QuizTest your understanding of how generative AI boosts productivity,…
Start QuizTest your knowledge of key API design fundamentals for…
Start QuizTest your understanding of caching basics for generated responses,…
Start QuizTest your understanding of basic caching concepts, including Time-to-Live…
Start QuizExplore key concepts in applying machine learning with JavaScript…
Start QuizSee how well you know the fundamentals of generative…
Start QuizExplore the fascinating basics of generative models with this…
Start QuizLevel up your understanding of core machine learning model…
Start QuizExplore the essentials of generative AI in this beginner-friendly…
Start QuizTest your knowledge of how generative AI powers smart…
Start QuizTest your knowledge of API design best practices, including resource modeling, request validation, versioning strategies, and idempotency. This quiz covers fundamental API concepts to help you build robust, user-friendly web services.
This quiz contains 16 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.
Which URL format best represents a RESTful resource for an individual user with an ID of 42?
Correct answer: /users/42
Explanation: The correct answer is /users/42, which clearly and concisely identifies a resource in RESTful API design. /getUser?id=42 and /users?id=42 use query parameters or action words, which are less RESTful. /user/42/details adds unnecessary detail to the path, making it less standard for retrieving a single user resource.
Which HTTP method is designed to be idempotent, meaning making the same request multiple times will have the same effect as once?
Correct answer: PUT
Explanation: PUT is idempotent, as sending the same data to a resource multiple times does not change its state beyond the first request. POST is not idempotent because it typically creates new resources; repeated POSTs may generate duplicates. CONNECT and TRACE are unrelated to resource modification and are rarely used in standard API design.
Why is input validation important when designing an API that accepts user data?
Correct answer: It prevents invalid or harmful data from entering the system.
Explanation: Input validation ensures only expected and correct data is processed, reducing the risk of errors or security flaws. Validation does not guarantee faster responses, cannot make the API entirely hack-proof, and does not perform language translation. Some options suggest unrealistic or incorrect outcomes.
According to API resource naming best practices, how should a collection of products be represented in the URI?
Correct answer: /products
Explanation: The plural noun '/products' correctly designates a collection of resources, which matches widely-accepted conventions. Using '/product' is typically for a single item. '/listproducts' and '/productsList' introduce verbs or unnecessary descriptors not standard in resource naming.
If an API request contains invalid input data, which HTTP status code should be returned?
Correct answer: 400 Bad Request
Explanation: 400 Bad Request indicates the server cannot or will not process the request due to user error, such as invalid input. 201 Created is for successful creation of resources, not failed requests. 301 Moved Permanently suggests a redirect, while 204 No Content implies a successful operation with no data returned.
Which of the following is a common and clear way to indicate API versioning within the URI?
Correct answer: /v1/orders
Explanation: Including the version as a prefix, such as '/v1/orders', is a widely-used and well-understood API versioning strategy. '/orders/vOne' uses a non-standard format, '/orders/version:1' is less conventional, and query parameters like '/orders?versioning=1' are usually not dedicated for major versioning.
When should an API client include an idempotency key in a request?
Correct answer: When retrying a POST request to avoid duplicate operations
Explanation: Idempotency keys are most important for POST requests that create or change resources, especially in scenarios like retries, to ensure no duplicate actions occur. Static resources don't modify data, so idempotency isn’t needed. GET and HEAD requests are already idempotent by definition.
In well-designed APIs, why should requests and responses be self-descriptive?
Correct answer: To reduce backend code complexity and help clients understand data without extra documentation
Explanation: Self-descriptive operations allow clients to understand what an API expects and returns, improving usability and reducing developer reliance on external references. Increasing server memory and limiting HTTP methods are unrelated, while security is not weakened by self-description.
What should an API do when a client sends a request with multiple invalid fields?
Correct answer: Return a single response listing all validation errors with helpful messages
Explanation: Good APIs report all detected validation errors in one response to help clients fix issues efficiently. Reporting only the first error is less user-friendly, ignoring errors can compromise data, and restarting the request is outside standard API behavior.
How should an API allow clients to filter a list of resources, such as filtering books by author?
Correct answer: By using query parameters, like /books?author=Alice
Explanation: Query parameters are the standard way to filter or search resource collections in APIs. Attaching filter actions to the path or requiring new endpoints is inefficient and against REST principles. GET requests should not use an HTTP body, so that option is invalid.
Why is the principle of statelessness important in API design?
Correct answer: It ensures that each request contains all information needed for processing without relying on server context.
Explanation: Statelessness mandates that requests are self-contained, making APIs scalable and easier to maintain. Saving previous requests in memory contradicts this principle, while the number of endpoints and authentication are unrelated to statelessness.
Which is a good practice for error response structure in modern APIs?
Correct answer: Returning a JSON body with an error code and message
Explanation: A structured JSON error with code and message is clear for clients to parse and act upon. Plain strings without proper status codes lack context, hiding all error details hinders debugging, and binary data is unreadable in most client contexts.
Which is NOT a recommended alternative to URI versioning for APIs?
Correct answer: Randomly changing endpoints with every version
Explanation: Randomizing endpoints breaks predictability and maintainability, making it unsuitable. Headers and query parameters are valid versioning alternatives; content negotiation via 'Accept' header is also widely used.
Which URI path correctly represents a sub-resource collection, such as all comments for a specific post with ID 7?
Correct answer: /posts/7/comments
Explanation: The format /posts/7/comments shows a sub-collection owned by a parent resource, following REST conventions. Using query parameters is more appropriate for filtering but not sub-resource collections, while the other options do not represent proper parent-child relationships.
Which HTTP method is considered safe as it should not modify resources?
Correct answer: GET
Explanation: GET is defined as safe because it is intended only to retrieve data, not to alter any server resources. PATCH, DELETE, and POST may alter server data, so they are considered unsafe methods in terms of modification potential.
Which scenario best illustrates an idempotent API operation?
Correct answer: Setting a user's email to 'a@example.com' using a PUT request multiple times
Explanation: Sending the same PUT request repeatedly with identical data results in the same resource state, demonstrating idempotency. Using POST to create resources can lead to duplication, which is not idempotent. PATCH with different data changes the resource each time, and deleting multiple items may have varying results depending on the resources' state.