HTTP u0026 REST Fundamentals for Database API Design Quiz

Test your knowledge of HTTP and REST essentials as they relate to database APIs. This quiz covers status codes, pagination practices, idempotency, and the use of ETags and If-Match headers to manage RESTful data operations effectively.

  1. Status Codes: Success Indication

    Which HTTP status code indicates a successful resource creation when using a POST request to a database API?

    1. 200 OK
    2. 201 Created
    3. 404 Not Found
    4. 301 Moved Permanently

    Explanation: The correct status code for a successful resource creation via POST is 201 Created, signifying that a new resource has been made. 200 OK is more general and usually signals a generic successful request, not specifically the creation of something new. 404 Not Found suggests the endpoint is missing, and 301 Moved Permanently refers to resource relocation, unrelated to successful creation.

  2. API Pagination Basics

    Which approach is most commonly used to paginate results in a RESTful database API when querying a large collection?

    1. Assigned page numbers to resources
    2. Using limit and offset query parameters
    3. Sending all results at once
    4. Including results in HTTP headers

    Explanation: Limit and offset query parameters allow clients to request only a subset of data, helping manage large result sets efficiently. Sending all results at once is not scalable for large datasets. Results are rarely included in HTTP headers due to size limits and practicality. Assigning page numbers to resources is non-standard and less flexible than using limit and offset.

  3. Idempotency of HTTP Methods

    Which HTTP method is considered idempotent and safe for deleting a database record?

    1. POST
    2. DELETE
    3. PATCH
    4. CONNECT

    Explanation: DELETE is an idempotent method in REST: repeating the same DELETE request produces the same result after the initial deletion. POST is generally not idempotent since it often creates resources. CONNECT is used for establishing tunnels, not typical database interactions. PATCH is for partial updates and is not guaranteed to be idempotent.

  4. Purpose of ETags

    What is the main purpose of using ETags in HTTP headers when interacting with database APIs?

    1. Data encryption
    2. Rate limiting
    3. Authentication
    4. Entity version control

    Explanation: ETags help manage version control of resources by providing a fingerprint representing the content version, ensuring safe updates and concurrent modification handling. They are not used for authentication, which secures user access. Data encryption and rate limiting have different purposes—protecting data privacy and controlling request frequency, respectively.

  5. If-Match Header Function

    When updating a database record using a RESTful PUT request, what does the If-Match HTTP header help prevent?

    1. Resource duplication
    2. Slow internet speeds
    3. Concurrent update conflicts
    4. Automatic login

    Explanation: If-Match ensures that updates occur only if the resource matches a specific ETag, protecting against lost updates from simultaneous users. It does not address slow internet speeds, which are unrelated to concurrency. Resource duplication is handled by other means, and automatic login is part of authentication, not HTTP conditional requests.

  6. Correct Use of HTTP Status Codes

    If a client tries to retrieve a database resource that does not exist, which HTTP status code should the API return?

    1. 409 Conflict
    2. 202 Accepted
    3. 401 Unauthorized
    4. 404 Not Found

    Explanation: 404 Not Found properly indicates that the requested resource does not exist on the server. 401 Unauthorized signals authentication failure, not absence of a resource. 409 Conflict refers to data conflicts, while 202 Accepted means the request is received but not processed yet, which is unrelated to missing resources.

  7. Safe Methods in REST

    Which HTTP method is typically classified as both safe and idempotent when used with database APIs for fetching data?

    1. PUT
    2. POST
    3. GET
    4. DELETE

    Explanation: GET is used to retrieve data without causing side effects, making it both safe (no resource modification) and idempotent (repeated requests yield the same result). PUT can modify or create resources, DELETE removes resources, and POST is not idempotent nor safe, as it often changes server state.

  8. Best Status for Successful Partial Update

    When a PATCH request successfully updates part of a database resource, which HTTP status code is most appropriate for the API to return?

    1. 204 No Content
    2. 305 Use Proxy
    3. 502 Bad Gateway
    4. 403 Forbidden

    Explanation: A successful PATCH request typically returns 204 No Content to indicate success without content in the response body. 403 Forbidden indicates lack of permissions, not success. 502 Bad Gateway reflects upstream server errors, and 305 Use Proxy is rarely used and unrelated to successful updates.

  9. Understanding HTTP Pagination Metadata

    What should a RESTful database API include to let clients efficiently navigate large paginated result sets?

    1. Tables in the request body
    2. Hard-coded sorting orders
    3. Random selection of pages
    4. Links or metadata for next and previous pages

    Explanation: Providing links or metadata about next and previous pages (in response headers or body) helps clients traverse paginated results easily. Including tables in the request body is not a standard navigation method. Random selection defeats pagination's purpose, and hard-coded sorting lacks the flexibility required for diverse client needs.

  10. Idempotency in Resource Creation

    To ensure idempotency when creating a resource via POST, what should an API require from the client?

    1. The entire database schema
    2. A password reset token
    3. A list of all previous requests
    4. A unique request identifier

    Explanation: A unique request identifier (like an Idempotency-Key header) allows the API to recognize repeated requests and avoid duplicate resource creation. Listing all previous requests is impractical and not standard. The database schema is unnecessary for individual requests, and a password reset token relates only to authentication, not idempotency.