Test your understanding of HTTP and REST fundamentals, including common status codes, the importance of idempotency in APIs, and best practices for API pagination. This quiz is designed for anyone wanting to review key concepts essential for robust web API design and operation.
Which HTTP status code indicates that a GET request was successful and data was returned?
Explanation: The 200 OK status code is used to show that a GET request was successful and the requested data is present in the response. A 301 Moved Permanently code indicates a permanent redirect, not data delivery. 404 Not Found means the resource doesn't exist, and 500 Server Error signals a generic server problem, not a successful request.
If a RESTful API returns '404 Not Found', what does it mean for the client request?
Explanation: A 404 Not Found response means the requested resource could not be located on the server. If the server were overloaded, a 503 or 502 code might fit better. A 'request is successful' status is indicated by 200. If data was created, 201 Created would be used.
Which definition best describes idempotency in HTTP methods?
Explanation: Idempotency means that making a request multiple times yields the same result as a single request, vital for safety in network retries. Requests that always fail or always change state are not idempotent. The presence of multiple parameters in a request is unrelated to idempotency.
Which HTTP method is generally considered idempotent when used correctly?
Explanation: PUT is idempotent, since sending the same data to the same URI multiple times does not change the final result. POST creates new resources and is not idempotent. CONNECT and TRACE are used for different purposes and are not standard for data manipulation in REST.
Why is pagination commonly used in REST APIs that return large lists of items?
Explanation: Pagination helps reduce the amount of data returned and optimizes performance by breaking large lists into smaller, more manageable pieces. It does not encrypt data or intentionally slow down retrieval. In fact, it reduces server load instead of increasing it.
What does the HTTP status code '201 Created' commonly signify in a RESTful API POST response?
Explanation: A 201 Created response indicates that the server has successfully created a new resource, often following a POST request. A rejected request would have a 4xx or 5xx code. 'Unmodified' typically uses 304 Not Modified, and deletions are often 204 No Content or 200 OK.
After successfully deleting a resource using a DELETE request, which HTTP status is commonly returned with no content?
Explanation: 204 No Content is the standard response for a successful resource deletion with no body returned. 202 Accepted means the request was received but not yet acted on. 410 Gone is for permanently unavailable resources. 301 Moved is unrelated to deletions and signals a redirect.
Which pair of query parameters is most commonly used together to implement basic pagination in REST APIs?
Explanation: The 'page' and 'limit' parameters enable clients to specify which page of results and how many items per page to retrieve. 'Order' and 'status' are for filtering or ordering data, not pagination. 'Sort' and 'filter' define sorting and filtering, not basic pagination. 'Token' and 'date' are not typically matched for pagination.
What does the HTTP status code 400 Bad Request usually indicate in the context of a RESTful API?
Explanation: A 400 Bad Request code tells the client they sent the wrong or incorrectly formatted data. A successful request would return 200, resource moves would use 302 or 307, and server memory problems typically generate a 500-level code.
If a client repeatedly sends the same valid PUT request to update a resource, how should the server respond according to HTTP and REST principles?
Explanation: For idempotent operations like PUT, the server should return the same result for identical requests, ensuring consistency. Creating duplicates is against PUT semantics. Rotating responses or ignoring requests would break idempotency and confuse clients.