HTTP u0026 REST Fundamentals Quiz Quiz

Test your knowledge of HTTP and REST basics with this quiz covering status codes, retries, timeouts, pagination, and idempotency. Ideal for beginners seeking to reinforce their understanding of essential web communication concepts and best practices.

  1. HTTP Status Codes

    Which HTTP status code indicates that a resource was not found on the server?

    1. 500
    2. 302
    3. 404
    4. 200

    Explanation: The 404 status code represents 'Not Found' and is returned when the requested resource does not exist on the server. 200 means a successful response, 302 indicates a temporary redirect, and 500 signifies a server error. Only 404 is used to report missing resources.

  2. RESTful Principles

    In REST APIs, what type of HTTP method is typically used to fetch data from a server?

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

    Explanation: GET requests are used to retrieve data from a server without causing any modification. POST is generally for creating resources, PUT for updating, and DELETE for removing. Only GET is suitable for simple data retrieval as described in REST.

  3. Timeout Mechanisms

    If an HTTP client sets a timeout of 10 seconds, what happens if the server takes 15 seconds to respond?

    1. The client stops waiting after 10 seconds
    2. The client waits until the server responds
    3. The request is automatically retried
    4. The server sends an error

    Explanation: A client-side timeout means the client stops waiting and typically ends the request after the specified period, regardless of the server's actions. The server does not control the timeout; also, no automatic retry or forced server error is standard. The most accurate behavior is the client stopping at its own timeout.

  4. Pagination Concept

    What is a common reason for implementing pagination in API responses when listing many items?

    1. To improve request speed and manage large datasets
    2. To change HTTP verbs
    3. To hide data
    4. To reduce status codes

    Explanation: Pagination divides large result sets into smaller chunks, which helps manage memory and network usage, and improves request performance. It is not for hiding data or altering verbs and has no direct connection with managing status codes.

  5. Status Code Identification

    Which HTTP status code indicates that the client's request was successfully received and processed?

    1. 301
    2. 200
    3. 201
    4. 400

    Explanation: A 200 status code signals a successful HTTP request. 201 means 'created' and is specific to resource creation, 301 is a permanent redirect, and 400 denotes a bad request. For a general successful operation, 200 is correct.

  6. Idempotency Definition

    Which statement best describes an idempotent HTTP method?

    1. It encrypts all data sent
    2. It bypasses server errors
    3. It compresses responses
    4. Sending the same request multiple times produces the same result

    Explanation: An idempotent method maintains the same effect no matter how often it is performed with the same input. Idempotency is unrelated to encryption, server error handling, or response compression, which are separate concepts.

  7. Retry Logic

    Why should automatic retries be limited when receiving an HTTP 500 status code?

    1. To avoid overloading the server
    2. Because the client made a mistake
    3. To save bandwidth only
    4. Because 500 means permanent failure

    Explanation: Excessive retries on server error responses like 500 can worsen server issues by increasing load. 500 indicates a temporary server error, not a permanent one, and is not caused by client mistakes. Saving bandwidth is a minor consideration compared to protecting server resources.

  8. Use of 201 Status Code

    Which scenario most appropriately uses the 201 HTTP status code?

    1. Fetching a list of users
    2. Attempting to update a missing resource
    3. Creating a new user account successfully
    4. Deleting a user account

    Explanation: 201 is used when a new resource, like a user account, is created successfully. Fetching data typically uses 200, deleting might use 204, and updating a missing resource could result in 404 or 400. Only the creation scenario matches 201.

  9. Proper Use of DELETE

    If you send multiple HTTP DELETE requests for the same resource, what should a correctly implemented RESTful API do?

    1. Change the status code to 201
    2. Return a success even if the resource no longer exists
    3. Delete the resource multiple times
    4. Fail after the first request

    Explanation: DELETE should be idempotent, so repeated requests have the same effect as a single one, usually responding with success even if the resource is gone. Deletes are not repeated, failures are not expected, and 201 is reserved for creation, not deletion.

  10. Pagination Parameters

    Which pair of URL query parameters is commonly used to implement pagination in REST APIs?

    1. retry and timeout
    2. query and filter
    3. limit and offset
    4. start and stop

    Explanation: 'limit' specifies the number of items to return, and 'offset' specifies how many to skip, making them common for pagination. 'retry' and 'timeout' relate to error handling, 'query' and 'filter' relate to searching, and 'start' and 'stop' are less standard.

  11. HTTP Headers for Pagination

    What is a typical header a REST API may use to indicate more pages are available?

    1. Content-Length
    2. X-Rate-Limit
    3. Link
    4. ETag

    Explanation: The Link header can provide next, previous, and other pagination-related URLs. X-Rate-Limit relates to throttling, ETag to caching and versioning, and Content-Length shows response size. Only Link is typical for pagination information.

  12. Safe HTTP Methods

    Which HTTP method should not change the server state and is considered 'safe'?

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

    Explanation: GET is safe and used only for retrieving data, without altering resources. POST, PATCH, and DELETE are designed to create, modify, or remove data, making them not 'safe' in HTTP’s terminology.

  13. HTTP Error Classifications

    Which status code class do codes beginning with '4' (e.g., 404) belong to in HTTP?

    1. Client Error
    2. Server Error
    3. Redirect
    4. Informational

    Explanation: Codes starting with '4' are Client Error codes, meaning the error originated from the client's side. 'Informational' covers 1xx, 'Server Error' is 5xx, and 'Redirect' is for 3xx. Only 'Client Error' matches 4xx codes like 404.

  14. Retry Scenarios

    Which HTTP status code is commonly considered safe to retry automatically?

    1. 401
    2. 502
    3. 201
    4. 400

    Explanation: 502 Bad Gateway indicates a temporary issue with upstream servers and is often recoverable by retrying. 401 is an authentication error, 400 is a client-side error, and 201 is a success code indicating resource creation, so only 502 is retryable.

  15. Idempotency of HTTP Methods

    Which HTTP method is defined as both idempotent and safe?

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

    Explanation: GET is both idempotent (repeating the request does not change the resource) and safe (it does not modify server state). PUT is idempotent but not safe, POST is neither, and PATCH is neither guaranteed safe nor idempotent.

  16. Handling Timeouts

    When a client-side timeout occurs before the server responds, what is the best practice for the client?

    1. Wait indefinitely
    2. Send a PATCH request instead
    3. Switch to another protocol
    4. Automatically retry with backoff

    Explanation: Retrying with exponential backoff (increasing wait times) helps avoid overwhelming the server and increases the chance of eventual success. Waiting indefinitely is not practical, switching protocols is not standard upon timeouts, and sending PATCH is unrelated.