HTTP Networking and REST APIs Quiz Quiz

Test your knowledge of key concepts in HTTP networking and REST APIs with this beginner-friendly quiz. Perfect for those seeking to understand request methods, status codes, headers, and best practices in modern web communication.

  1. Question 1

    Which HTTP method is most appropriate for retrieving data from a REST API without modifying any resources?

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

    Explanation: GET is used to request data from a server without causing any changes to the server state. POST is meant for submitting data and may create resources, while DELETE removes resources. PUSH is not a standard HTTP method in RESTful APIs. Choosing GET ensures safe, read-only operations.

  2. Question 2

    What does the HTTP status code 404 indicate when interacting with a REST API endpoint?

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

    Explanation: The 404 status code means that the requested resource could not be found on the server. 'Request successful' is represented by 200, 'Bad request' by 400, and 'Internal server error' by 500. Using 404 clearly communicates a missing resource to the client.

  3. Question 3

    Which of the following is a typical format used for sending structured data in REST API requests and responses?

    1. MP3
    2. JPEG
    3. JSON
    4. HTML

    Explanation: JSON (JavaScript Object Notation) is widely used for structured data exchange in REST APIs due to its readability and compatibility. JPEG and MP3 are media file formats not suitable for data structures, while HTML is used for web pages instead of structured API data.

  4. Question 4

    In RESTful design, which HTTP method should be used to update part of an existing resource?

    1. TRACE
    2. FETCH
    3. SAVE
    4. PATCH

    Explanation: PATCH is intended for partial updates to existing resources in REST APIs. TRACE is used for diagnostic tracing, FETCH and SAVE are not standard HTTP methods. PATCH allows sending just the changes, making it efficient for partial modifications.

  5. Question 5

    What is the function of the 'Content-Type' header in an HTTP request to a REST API?

    1. It sets password protection
    2. It tells the server the format of the request body
    3. It declares request priority
    4. It tracks server error logs

    Explanation: The 'Content-Type' header specifies the media type of the request payload, letting the server know how to interpret incoming data. It does not declare request priority, set password protection, or handle error logging. Proper use ensures accurate data parsing.

  6. Question 6

    Which URL path correctly represents the RESTful way to get information about a specific user with ID 15?

    1. /user-15/info
    2. /fetch/user15
    3. /getUser?id=15
    4. /users/15

    Explanation: /users/15 follows RESTful conventions by using a noun (users) and the ID in the path. /getUser?id=15 uses query parameters, which is not the typical REST resource identification. /user-15/info and /fetch/user15 are not standardized REST resource paths.

  7. Question 7

    If a REST API returns the status code 201 after making a POST request, what does this usually mean?

    1. There was a timeout
    2. A new resource has been created
    3. The resource was deleted
    4. The request is unauthorized

    Explanation: A 201 status code signifies that a new resource was successfully created as a result of the POST request. Unauthorized requests are indicated by 401, deletions typically return 204, and timeouts return 408. 201 is specific to successful creation actions.

  8. Question 8

    Which header is usually included in HTTP requests to send authentication information to a REST API?

    1. Expires
    2. Location
    3. Cookiee
    4. Authorization

    Explanation: The 'Authorization' header is standard for passing authentication credentials, such as tokens, in API requests. 'Location' is used for redirect URLs, 'Expires' controls caching, and 'Cookiee' is a typo and not a valid header. Proper authentication relies on the Authorization header.

  9. Question 9

    What does the principle of 'statelessness' mean in the context of REST APIs?

    1. The API always responds in the same way
    2. The server maintains user sessions between requests
    3. Each API request contains all necessary info for the server to process it
    4. Only GET requests are allowed

    Explanation: Statelessness means the server does not remember previous client requests; each request must stand alone with all required data. It does not mean uniform responses, ongoing user session storage (which is stateful), or limiting to GET requests. This improves scalability and reliability.

  10. Question 10

    Which HTTP status code is returned when the request is syntactically incorrect or cannot be processed by the server?

    1. 203
    2. 302
    3. 100
    4. 400

    Explanation: A 400 status code represents a 'Bad Request,' indicating the request is malformed or invalid. 100 is an informational status, 302 is for redirects, and 203 means 'Non-Authoritative Information.' 400 signals issues with the request's syntax or data.