Test your understanding of HTTP/REST ingestion design principles, including idempotency, pagination strategies, retry mechanisms, and status codes. This quiz is perfect for anyone wanting to sharpen their skills in designing and consuming reliable APIs using REST.
Which HTTP method is typically considered idempotent when used for updating a resource, for example, updating a user's profile?
Explanation: The PUT method is idempotent because sending the same request multiple times results in the same resource state. POST is not idempotent since it can create multiple resources. PATCH is only partially idempotent and may yield different results depending on implementation. CONNECT is used for establishing tunnels and is unrelated to resource modifications.
When implementing cursor-based pagination in a REST API, what is the main purpose of the 'cursor'?
Explanation: A cursor in pagination acts as a pointer to the next set of results for efficient traversal, especially when data might change between requests. HTTP versioning is not managed by cursors. User sessions are unrelated to cursor functionality, and resource attributes are not stored in cursors.
Why should an API client include an idempotency key when making POST requests that may be retried, such as for payment processing?
Explanation: Idempotency keys ensure that repeated requests with the same key do not result in duplicate operations, which is crucial for actions like payments. Network speed is unrelated to idempotency. Encryption should use other mechanisms like HTTPS, and client device type tracking is not related here.
Which scenario best describes a situation where automatic retries are recommended during HTTP ingestion?
Explanation: Automatic retries are suitable for transient errors, such as network timeouts, because the request might succeed later. Authorization failures require correcting permissions, not retries. Malformed data needs client correction. Resource deletions are intentional and should not be repeated automatically.
If a request is not idempotent, what can happen if it is automatically retried by the client?
Explanation: Non-idempotent requests, like many POST operations, can cause side effects such as creating multiple records when retried. Retries do not inherently speed up APIs, correct data, or improve security; in fact, they may introduce new problems if not handled carefully.
Which HTTP status code should an API return to indicate that a client request has been accepted for processing, but is not yet completed?
Explanation: The 202 Accepted status code signals that a request is valid and in process, but not finished. 200 OK shows immediate success, 404 Not Found means the resource is missing, and 503 Service Unavailable signals a server issue, not in-progress work.
What is the main disadvantage of offset-based pagination (using limit and offset) for very large datasets?
Explanation: Offset-based pagination may suffer from slow performance and inconsistent results due to shifting data in large tables. It does not block concurrent access, nor does it directly break REST principles. Encryption concerns are unrelated to pagination style.
If a REST API responds with a 429 Too Many Requests status, which header should clients check to determine when to retry?
Explanation: The Retry-After header tells clients how long to wait before retrying after receiving a 429. Location is for resource redirecting, Content-Type specifies data type, and Authorization handles access, not retry timing.
Which HTTP status code indicates that a new resource has been successfully created by a POST request?
Explanation: 201 Created is used when a resource is newly created, typically after a POST request. 204 No Content means success with no return data, 301 is for redirects, and 500 is a server error, not related to successful creation.
How can an API make repeated POST requests safer in the context of network interruptions?
Explanation: Idempotency keys prevent repeated POSTs from creating duplicate results. Removing authentication introduces security risks. Using GET fails to perform resource creation, and returning 404 does not address safe retry handling.
What does 'backfill' mean in the context of REST ingestion and data pipelines?
Explanation: Backfill is the process of capturing data that was missed in earlier ingestion runs, often due to outages or sync issues. It does not involve encryption, deleting data, or response size limits, which are separate concerns.
When requesting a backfill of data in a REST API, which HTTP method is typically used to fetch historical resources without side effects?
Explanation: The GET method retrieves data without causing changes, making it suitable for fetching historical records. DELETE would remove resources, not retrieve them. OPTIONS describes operations, and PATCH is for partial updates.
What does the 304 Not Modified status code indicate in a typical REST response?
Explanation: 304 Not Modified means the data hasn't changed, often used with caching headers. It is not related to authentication, deletion, or resource creation, each of which has its own distinct status codes.
Why is statelessness important when designing pagination in REST APIs?
Explanation: Statelessness ensures that the server does not need to retain information about past requests, enabling scalability and simplicity. Encryption is unrelated to statelessness. Performance improvements and firmware updates are not direct outcomes of stateless pagination design.
If an API client submits a request with invalid or missing required data, which status code should be returned?
Explanation: 400 Bad Request is the standard code for invalid client-supplied data. 307 Temporary Redirect is for URL redirection, 201 is for successful creation, and 408 indicates a client-side timeout, none of which fit this scenario.
What is the main advantage of using exponential backoff in API retries?
Explanation: Exponential backoff spaces out retries, helping to avoid server congestion during outages. It does not directly speed up retries, encrypt messages, or prevent data duplication, all of which require different techniques.