HTTP u0026 REST Fundamentals Quiz Quiz

Test your knowledge of HTTP and REST basics with this quiz covering HTTP verbs, status codes, idempotency, pagination, and error handling. Ideal for those seeking a foundational understanding of RESTful APIs and HTTP operations.

  1. Identifying the Correct HTTP Verb

    Which HTTP verb should you use to retrieve data about a user profile without making any changes to it?

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

    Explanation: GET is used to fetch data from a server without causing side effects. POST is for creating new resources, PUT is for updating existing resources, and DELETE removes resources. Only GET is designed specifically for safe data retrieval, making it the most appropriate choice.

  2. Meaning of the 404 Status Code

    What does the HTTP status code 404 indicate when accessing a RESTful API endpoint?

    1. Resource not found
    2. Request successful
    3. Resource created
    4. Internal server error

    Explanation: A 404 status code means the requested resource could not be found on the server. 'Request successful' corresponds to 200, 'Internal server error' refers to 500, and 'Resource created' is indicated by 201. Therefore, only 'Resource not found' fits 404.

  3. Understanding Idempotency

    Which HTTP method is considered idempotent when updating a resource, meaning repeated identical requests have the same effect as one?

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

    Explanation: PUT is idempotent because sending the same PUT request multiple times results in the resource being updated to the same state each time. POST is not idempotent as it usually creates new resources, CONNECT is used for opening a tunnel (not updating resources), and PATCH is generally not guaranteed to be idempotent. Only PUT fits this idempotency guarantee.

  4. Appropriate Use of the DELETE Verb

    If you want to remove a specific item from a RESTful API, which HTTP verb should you use?

    1. TRACE
    2. DELETE
    3. OPTIONS
    4. HEAD

    Explanation: DELETE is the correct verb for removing a resource in RESTful APIs. TRACE is used for diagnostic purposes, HEAD fetches only headers, and OPTIONS returns allowed HTTP methods. Only DELETE performs removal operations.

  5. Status Code for Successful Creation

    What HTTP status code is typically returned after successfully creating a new resource using a POST request?

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

    Explanation: 201 indicates that a new resource has been created. 400 is for bad requests, 301 is for redirects, and 204 signals no content but does not indicate resource creation. Only 201 is correct for new resource creation acknowledgment.

  6. Purpose of Pagination in REST APIs

    Why do REST APIs commonly use pagination when returning large lists of data, such as a list of posts or products?

    1. To increase server errors
    2. To encrypt transmitted data
    3. To hide sensitive data
    4. To limit response size and improve performance

    Explanation: Pagination reduces the amount of data sent in one response, making responses faster and more manageable. Hiding sensitive data and encrypting data involve security, not pagination. Increasing server errors is not an aim of pagination, making only 'To limit response size and improve performance' correct.

  7. Interpreting Status Code 500

    If a REST API returns a 500 status code after a request, what does this mean?

    1. The resource was redirected
    2. The client is unauthorized
    3. The request was successful
    4. The server encountered an internal error

    Explanation: A 500 status code signals an internal server error, usually indicating something went wrong on the server side. 'Redirected' corresponds to 3xx codes, 'Unauthorized' is 401, and 'Successful' is usually 200. Only the server error explanation fits code 500.

  8. How to Specify Pagination Parameters

    Which query parameters are commonly used for simple pagination in a RESTful API when fetching lists?

    1. source and value
    2. limit and offset
    3. token and state
    4. code and type

    Explanation: The 'limit' and 'offset' parameters are standard for defining how many items to retrieve (limit) and where to start (offset). 'Code and type' or 'source and value' are not typical for pagination, and 'token and state' may be used in authentication or workflow, not pagination. 'Limit and offset' are the well-known standard.

  9. Correct Use of Status Code 400

    If a client sends malformed or invalid input to a RESTful API, which HTTP status code should the server respond with?

    1. 403
    2. 202
    3. 302
    4. 400

    Explanation: 400 indicates a bad request due to invalid or incorrect input from the client. 403 means forbidden access, 202 means the request has been accepted for processing, and 302 signals temporary resource redirection. 400 directly relates to client input errors.

  10. Difference Between PUT and PATCH

    When you want to update only a few fields of a resource in a RESTful API without replacing the entire resource, which HTTP verb should you use?

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

    Explanation: PATCH is used to make partial updates, changing only specified fields. PUT replaces the entire resource with new data, GET is for retrieval with no changes, and CONNECT establishes tunnel connections, which are unrelated to updating resources. PATCH is the method designed for partial modifications.