HTTP u0026 REST Fundamentals Quiz Quiz

Challenge your understanding of HTTP and REST basics, including request/response flow, status codes, idempotency, pagination, and retry strategies. This quiz helps you assess core concepts in building and maintaining robust RESTful APIs.

  1. Identifying HTTP Methods

    Which HTTP method is generally used to retrieve data from a server without modifying any resources, such as fetching user details?

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

    Explanation: GET is used to request and retrieve data from the server without changing it. POST is intended for creating new resources, which alters the state of the server. DELETE removes a resource, and PATCH updates part of a resource. Only GET guarantees no modifications are made.

  2. Interpreting Status Codes

    What does an HTTP status code of 201 indicate after a client creates a new object?

    1. Moved Permanently
    2. No Content
    3. Accepted
    4. Created

    Explanation: The 201 Created status code signals that a resource has been successfully created as a result of the request. 'Moved Permanently' (301) relates to redirection, 'Accepted' (202) means the request was received but not yet acted upon, and 'No Content' (204) indicates success with no message body.

  3. Understanding Idempotency

    Which HTTP method is designed to be idempotent, meaning making the same request multiple times produces the same result, such as multiple deletions of an item?

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

    Explanation: DELETE is idempotent because deleting the same resource multiple times has the same effect as deleting it once. POST is not idempotent, as it usually creates a new resource each time. CONNECT and TRACE are specialized methods not typically associated with resource manipulation.

  4. Request and Response Flow

    In a typical HTTP request/response flow, where are request headers located, and what purpose do they serve?

    1. At the start of the request, containing metadata such as authentication or content type
    2. At the end of the response, providing error codes
    3. Within the request body, identifying user credentials
    4. After the status code in the response, returning the requested resource

    Explanation: Request headers appear at the beginning of an HTTP request and carry important metadata. They are not located in the body, nor are they part of the end of the response or just after the status code. Response headers, not request headers, are sent back after the status code.

  5. Choosing Status Codes for Errors

    If a client requests a non-existent resource, which HTTP status code should the server return?

    1. 201 Created
    2. 404 Not Found
    3. 500 Internal Error
    4. 200 OK

    Explanation: The 404 Not Found code tells the client that the requested resource does not exist. 200 OK means the request succeeded, which is inaccurate here. 201 Created is for successful resource creation, and 500 Internal Error signals a server malfunction, not a missing resource.

  6. Implementing Pagination

    Which approach is commonly used in REST APIs to provide pagination when returning large data sets, such as a list of products?

    1. Repeating the request with a different HTTP method
    2. Limit and offset parameters in the query string
    3. Sending all results in a single large response
    4. Encoding results into binary blobs

    Explanation: Adding 'limit' and 'offset' to the query string enables pagination, returning only a subset of data per request. Sending all results at once is inefficient and impractical for large datasets. Changing the HTTP method or using binary blobs are not relevant or standard for API pagination.

  7. Interpreting Retry and Backoff Strategies

    When a server responds with a 429 Too Many Requests status code, what is a recommended next step for the client?

    1. Ignore the response and proceed with other requests
    2. Wait before retrying, possibly using exponential backoff
    3. Change the request method from GET to POST
    4. Immediately retry the same request multiple times

    Explanation: A 429 status means the client should slow down; implementing a delay or exponential backoff helps avoid further rate limiting. Repeated immediate retries may worsen the problem, and changing the method or ignoring the response doesn't resolve excessive requests.

  8. Best Practices for Safe Methods

    Which HTTP method is considered 'safe,' meaning it should only retrieve data and not cause any changes on the server, even if used many times?

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

    Explanation: GET is classified as a safe method as it solely fetches data without any side effects. PUT and DELETE can modify or remove resources, and POST usually creates or processes data, making them not safe methods.

  9. Identifying Success Status Codes

    If an API responds with a 204 No Content status after a DELETE request, what does this convey to the client?

    1. An error occurred, and more information is needed
    2. The resource was partially deleted with some data remaining
    3. A new resource was created, but no content is returned
    4. The resource was successfully deleted, and there is no message body in the response

    Explanation: A 204 No Content status indicates a successful request with no further content to return, which is typical after deleting a resource. It's not an error, it doesn't suggest a partial deletion, and it doesn't relate to resource creation.

  10. Understanding Cache in RESTful APIs

    Which HTTP header can be used by the server to tell clients how long a response can be cached, for example when serving static images?

    1. Referer
    2. Cache-Control
    3. Content-Disposition
    4. Allow

    Explanation: Cache-Control dictates caching policies, such as how long a response can be stored by the client. Allow specifies supported HTTP methods, Referer shows the origin of the request, and Content-Disposition manages how content should be presented or downloaded, unrelated to caching.