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

Test your knowledge of HTTP and REST fundamentals, including status codes, pagination techniques, and the principles of idempotency. This quiz is designed for learners seeking to understand essential concepts for building and consuming web APIs effectively.

  1. Understanding 200 OK

    What does the HTTP status code 200 OK signify when a client sends a GET request to an API endpoint?

    1. The client is unauthorized to access the resource.
    2. The request was successful and the resource is returned.
    3. The resource was not found on the server.
    4. An internal server error occurred.

    Explanation: The status code 200 OK is sent when a request has succeeded and the server returns the requested resource. A 404 code means the resource was not found, which is different. A 500 status code indicates an internal server error, and 401 means the client must authenticate themselves, not that the request succeeded.

  2. 404 Not Found Scenario

    Which HTTP status code should a server return if a client requests a resource that does not exist?

    1. 202 Accepted
    2. 201 Created
    3. 301 Moved Permanently
    4. 404 Not Found

    Explanation: When a resource is not available on the server, a 404 Not Found response is appropriate. The 201 Created status is used when something new is created, not for missing resources. 301 indicates a permanent redirect, which doesn’t fit this case. 202 Accepted means the request has been received but not yet processed.

  3. POST vs GET Methods

    Which HTTP method is typically used to submit data that creates a new resource, such as submitting a new user registration form?

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

    Explanation: POST is the method designed for creating new resources by submitting data to the server. GET is used for retrieving information, not submitting data that will change the server state. DELETE removes resources, while PATCH is intended for partial updates.

  4. Idempotent Methods Identification

    Which of the following HTTP methods is considered idempotent when interacting with an API endpoint?

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

    Explanation: PUT is idempotent because calling it multiple times with the same data will always result in the resource having the same state. POST is not idempotent because multiple POSTs can create multiple resources. CONNECT establishes a tunnel, which is not idempotent, and OPTIONS is used to describe communication options and doesn't actually modify resources.

  5. Purpose of 201 Created

    If an API successfully creates a new resource upon receiving data, which status code should it return?

    1. 301 Moved Permanently
    2. 403 Forbidden
    3. 204 No Content
    4. 201 Created

    Explanation: A 201 Created response is appropriate when a resource has been successfully created. 204 No Content would indicate that the request was successful but there is no response body, which is not as descriptive. 301 is for redirection, and 403 means the client is not allowed to access the resource.

  6. Understanding Pagination

    Why is pagination commonly used when retrieving a large list of resources from a REST API?

    1. To encrypt API responses
    2. To break up large data sets into manageable chunks for performance and efficiency
    3. To allow simultaneous creation and deletion of resources
    4. To collect user authentication information

    Explanation: Pagination helps prevent overwhelming both the server and clients by limiting the amount of data returned in a single response, making data retrieval more efficient. It is not used for authentication, nor does it relate to encrypting responses or handling simultaneous resource creation and deletion.

  7. HTTP 204 No Content Usage

    After a successful DELETE request, which HTTP status code is most appropriate if no further content needs to be returned?

    1. 204 No Content
    2. 403 Forbidden
    3. 302 Found
    4. 412 Precondition Failed

    Explanation: 204 No Content is used to indicate that the request was successful, but the server is not returning any content. 403 would mean the client lacks permission, 302 is for temporary redirects, and 412 refers to preconditions that failed, none of which apply to a completed DELETE action.

  8. Detecting Bad Requests

    Which HTTP status code indicates that there was something wrong with the client's request, such as missing required fields or malformed JSON?

    1. 406 Not Acceptable
    2. 307 Temporary Redirect
    3. 400 Bad Request
    4. 504 Gateway Timeout

    Explanation: The 400 Bad Request code is used when the server cannot understand the request due to invalid syntax or missing data. 406 means the server cannot send the requested content type, 307 is for redirects, and 504 concerns gateway timeouts, not client request errors.

  9. Correct Use of 401 Unauthorized

    Which situation best matches returning a 401 Unauthorized status code from a REST API?

    1. When a client provides no valid authentication credentials
    2. When a server finishes processing a request with no content to return
    3. When a client requests an unsupported media type
    4. When the server cannot find the requested resource

    Explanation: 401 Unauthorized is used when authentication is required and has failed or has not yet been provided. Unsupported media types should return 415, missing resources should return 404, and completed requests with no content should use 204, not 401.

  10. Meaning of 405 Method Not Allowed

    If a client tries to use the PATCH method on a resource that only supports GET and POST, which status code should the server return?

    1. 501 Not Implemented
    2. 203 Non-Authoritative Information
    3. 405 Method Not Allowed
    4. 200 OK

    Explanation: 405 Method Not Allowed tells the client that the method is recognized but not allowed for the requested resource. 200 would incorrectly indicate success, 203 is not relevant in this context, and 501 is used if the method itself is not recognized by the server, which is not the case here.

  11. Default Pagination Parameters

    Which pair of query parameters is most commonly used for pagination in REST APIs?

    1. accept and content-type
    2. username and password
    3. filter and sort
    4. page and limit

    Explanation: The parameters 'page' and 'limit' are widely used to specify the page number and the number of items per page. 'username' and 'password' are used for authentication. 'filter' and 'sort' may help with querying but are not default pagination parameters. 'accept' and 'content-type' are HTTP headers for content negotiation.

  12. Idempotency Example

    If a PUT request to /users/22 with the same payload is sent twice, what should happen according to idempotency?

    1. A new user is created each time
    2. The user is deleted after the second request
    3. The user resource ends up in the same state after each request
    4. The server always returns an error

    Explanation: Idempotency means that applying the same request multiple times results in the same effect as applying it once. PUT updates or creates the user in a specific state, so repeating it does not further change anything. POST creates new resources, which would not be idempotent. Returning errors or deleting users after subsequent identical requests does not align with REST principles.

  13. Safe Methods in HTTP

    Which HTTP method is classified as safe, meaning it should not have side effects on the resource?

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

    Explanation: GET is considered safe because it is solely for retrieving data and should not modify any resources on the server. DELETE, PUT, and POST may change server data and are not classified as safe methods.

  14. Role of 429 Too Many Requests

    What does the HTTP status code 429 Too Many Requests indicate when returned from a REST API?

    1. Authentication credentials are missing
    2. The server has no content to return
    3. The client has sent too many requests in a given amount of time
    4. The resource has been permanently removed

    Explanation: 429 Too Many Requests is used by servers to indicate that the user has sent too many requests in a given period, often due to rate limiting. No content to return should use 204. Missing credentials return a 401. Permanent removal would use 410 Gone.

  15. Selecting 503 Service Unavailable

    Which condition is best described by the HTTP status code 503 Service Unavailable?

    1. The server successfully deleted the resource
    2. The server is temporarily unable to handle the request due to maintenance or overload
    3. The request requires user authentication
    4. The resource was created successfully

    Explanation: 503 indicates the server cannot process the request now, often due to temporary overload or scheduled maintenance. 201 would be used for resource creation. 401 is for authentication issues. Successful deletion would use 204 No Content.

  16. Partial Update Method

    What HTTP method is commonly used for partial updates to an existing resource in a REST API?

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

    Explanation: PATCH is designed for making partial changes to a resource, updating only specified fields. DELETE is for removing resources altogether. TRACE and CONNECT are diagnostic and low-level networking methods, not intended for resource modifications.