HTTP and REST Basics: Status Codes, Pagination, Idempotency Quiz

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.

  1. Identifying Success Status Codes

    Which HTTP status code indicates that a GET request was successful and data was returned?

    1. 500 Server Error
    2. 301 Moved Permanently
    3. 200 OK
    4. 404 Not Found

    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.

  2. Understanding Resource Not Found

    If a RESTful API returns '404 Not Found', what does it mean for the client request?

    1. The resource does not exist
    2. The request is successful
    3. The server is overloaded
    4. The data was created

    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.

  3. Describing Idempotency

    Which definition best describes idempotency in HTTP methods?

    1. The request always fails after the first time
    2. The request must include multiple parameters
    3. Every request changes server state
    4. Making the same request multiple times has the same effect as once

    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.

  4. Choosing an Idempotent HTTP Method

    Which HTTP method is generally considered idempotent when used correctly?

    1. POST
    2. TRACE
    3. PUT
    4. CONNECT

    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.

  5. Best Practices in Pagination

    Why is pagination commonly used in REST APIs that return large lists of items?

    1. To improve performance and reduce response size
    2. To increase server load
    3. To make data retrieval slower
    4. To encrypt the data

    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.

  6. Interpreting 201 Created

    What does the HTTP status code '201 Created' commonly signify in a RESTful API POST response?

    1. The server rejected the request
    2. The resource is unmodified
    3. A new resource has been successfully created
    4. The resource was deleted

    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.

  7. Choosing the Right Status for Deletions

    After successfully deleting a resource using a DELETE request, which HTTP status is commonly returned with no content?

    1. 301 Moved
    2. 202 Accepted
    3. 204 No Content
    4. 410 Gone

    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.

  8. Pagination Parameters Example

    Which pair of query parameters is most commonly used together to implement basic pagination in REST APIs?

    1. token and date
    2. page and limit
    3. order and status
    4. sort and filter

    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.

  9. Meaning of 400 Bad Request

    What does the HTTP status code 400 Bad Request usually indicate in the context of a RESTful API?

    1. The server ran out of memory
    2. The request completed successfully
    3. The client sent invalid or malformed data
    4. The resource has moved temporarily

    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.

  10. Ensuring Idempotency with PUT

    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?

    1. It should rotate the response codes
    2. It should eventually ignore the requests
    3. It should return the same outcome each time
    4. It should create multiple duplicate resources

    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.