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.
Which HTTP method is most appropriate for retrieving data from a REST API without modifying any resources?
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.
What does the HTTP status code 404 indicate when interacting with a REST API endpoint?
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.
Which of the following is a typical format used for sending structured data in REST API requests and responses?
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.
In RESTful design, which HTTP method should be used to update part of an existing resource?
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.
What is the function of the 'Content-Type' header in an HTTP request to a REST API?
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.
Which URL path correctly represents the RESTful way to get information about a specific user with ID 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.
If a REST API returns the status code 201 after making a POST request, what does this usually mean?
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.
Which header is usually included in HTTP requests to send authentication information to a REST API?
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.
What does the principle of 'statelessness' mean in the context of REST APIs?
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.
Which HTTP status code is returned when the request is syntactically incorrect or cannot be processed by the server?
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.