HTTP u0026 REST Fundamentals Quiz Quiz

Test your knowledge of HTTP and REST basics, including status codes, pagination techniques, and idempotency concepts. This quiz covers essential topics for anyone looking to strengthen their understanding of web APIs and client-server communication.

  1. Status Code Meaning

    What does the HTTP status code 404 represent when a client sends a request for a resource?

    1. Moved Permanently
    2. Not Found
    3. Bad Gateway
    4. Forbidden

    Explanation: 404 means 'Not Found,' indicating the requested resource does not exist on the server. 'Bad Gateway' (502) is used for gateway or proxy errors, 'Moved Permanently' (301) signals that a resource has a new URL, and 'Forbidden' (403) means the server is refusing to fulfill the request. Only 'Not Found' aligns with a resource being absent.

  2. Success Status Code

    Which HTTP status code indicates a successful GET request?

    1. 201 Created
    2. 301 Moved
    3. 200 OK
    4. 400 Bad Request

    Explanation: A 200 OK status code tells the client that the request was successful and the server returned the requested data. 201 Created is used after a successful resource creation, 301 Moved indicates a permanent redirection, and 400 Bad Request reflects a client-side error in the request. Only 200 OK fits a typical successful GET.

  3. REST Resource Naming

    In RESTful API design, which URL format is preferred for accessing a list of books?

    1. /books
    2. /books/list
    3. /bookList
    4. /getBooks

    Explanation: RESTful design encourages the use of nouns and plural resource names, so '/books' is standard for a collection endpoint. '/getBooks' uses a verb, which is discouraged. '/bookList' is less conventional and '/books/list' could imply a sub-resource rather than the main collection.

  4. Pagination Purpose

    What is the primary reason for implementing pagination in a RESTful API?

    1. To convert JSON to XML
    2. To increase the status code range
    3. To encrypt the response data
    4. To limit the number of items returned in a response

    Explanation: Pagination is used to control how many results are returned in a single API response, improving performance and usability. Encryption deals with security, not pagination. Converting formats and increasing status code range are unrelated to pagination in REST APIs.

  5. Idempotency Concept

    Which HTTP method is typically considered idempotent, meaning repeated identical requests have the same effect as one request?

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

    Explanation: PUT is idempotent because sending the same PUT request multiple times results in the same resource state. POST creates new resources and is not idempotent. PATCH can make partial changes and may not be idempotent. CONNECT is used for establishing network connections and is rarely idempotent.

  6. 201 Created Usage

    After successfully creating a new user resource, which HTTP status code should the server return?

    1. 400 Bad Request
    2. 500 Internal Error
    3. 201 Created
    4. 204 No Content

    Explanation: 201 Created clearly informs the client that a new resource was made. 204 No Content is used when there's no response body, usually after deleting resources. 400 means there was a client error, and 500 indicates a server-side error. Only 201 Created is appropriate after successful resource creation.

  7. Safe Methods

    Which HTTP method is considered 'safe' because it should not alter the state of the server?

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

    Explanation: GET requests retrieve data without changing anything on the server, making them 'safe.' DELETE removes resources, PUT modifies or updates them, and PATCH makes partial changes, so these are not classified as safe.

  8. Standard REST Status

    What status code should a server use to respond to a successful DELETE request with no content?

    1. 204 No Content
    2. 200 OK
    3. 302 Found
    4. 202 Accepted

    Explanation: 204 No Content is intended for successful requests where there's nothing to show in the response body, such as after a DELETE. 200 OK is more general but usually used with a response body. 302 Found is for redirection, and 202 Accepted indicates a request has been received for processing but isn't complete.

  9. HTTP Verbs and CRUD

    Which HTTP method is mainly used to retrieve data from a server in a REST API?

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

    Explanation: GET is designed for data retrieval in RESTful APIs. POST is for sending data to create resources. PATCH is for partial updates, and TRACE is primarily used for diagnostic purposes, not data retrieval.

  10. Incorrect Status Code

    Which one of these is NOT a valid HTTP status code?

    1. 404 Not Found
    2. 299 Custom OK
    3. 201 Created
    4. 500 Internal Server Error

    Explanation: 299 is not a standard HTTP status code. 404, 201, and 500 are all part of the official HTTP status code ranges. While some servers may use custom codes, 299 does not exist in the standard specification.

  11. Pagination in URLs

    Which query parameters are commonly used for pagination in RESTful APIs?

    1. auth and token
    2. page and limit
    3. sort and filter
    4. id and key

    Explanation: 'page' and 'limit' are widely used to control pagination, telling the server which set of results and how many to return. 'auth' and 'token' are used for authentication. 'id' and 'key' usually identify resources. 'sort' and 'filter' manage sorting and filtering, not pagination.

  12. Common Error Response

    When a client sends a malformed request to a REST API, which status code should be returned?

    1. 400 Bad Request
    2. 202 Accepted
    3. 403 Forbidden
    4. 301 Moved Permanently

    Explanation: 400 Bad Request directly indicates that the client sent a request the server could not understand or process. 403 is for denied access, 202 means the request is being processed, and 301 relates to resource redirection, none of which fit a malformed request.

  13. Location Header

    When creating a resource with POST, which response header typically provides the URL of the new resource?

    1. Referer
    2. Location
    3. Range
    4. Cookie

    Explanation: The 'Location' header in the HTTP response informs the client where the new resource can be accessed. 'Referer' tracks the previous page, 'Cookie' relates to client state, and 'Range' is for partial content responses.

  14. Idempotency Safe Method

    Which of the following HTTP methods is both safe and idempotent?

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

    Explanation: GET is safe because it does not alter resources and idempotent because multiple identical GETs have the same effect as one. PUT and DELETE are idempotent but not safe, as they change server state. OPTIONS is safe but used for discovering server capabilities, not resource manipulation.

  15. Partial Update Method

    Which HTTP method is used to partially update a resource in a RESTful API?

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

    Explanation: PATCH enables partial updates to resources, making it distinct from PUT, which updates the full resource. POST is meant for creating resources. TRACE is a diagnostic tool, not used for updating resources.

  16. Client Error Codes

    Which range of HTTP status codes represents client errors?

    1. 500–599
    2. 400–499
    3. 100–199
    4. 200–299

    Explanation: 400–499 denotes client errors like bad requests or unauthorized access. 100–199 is for informational purposes, 200–299 for successes, and 500–599 covers server errors. Only 400–499 directly corresponds to client-side mistakes.