Test your knowledge of HTTP and REST basics with this quiz covering status codes, retries, timeouts, pagination, and idempotency. Ideal for beginners seeking to reinforce their understanding of essential web communication concepts and best practices.
Which HTTP status code indicates that a resource was not found on the server?
Explanation: The 404 status code represents 'Not Found' and is returned when the requested resource does not exist on the server. 200 means a successful response, 302 indicates a temporary redirect, and 500 signifies a server error. Only 404 is used to report missing resources.
In REST APIs, what type of HTTP method is typically used to fetch data from a server?
Explanation: GET requests are used to retrieve data from a server without causing any modification. POST is generally for creating resources, PUT for updating, and DELETE for removing. Only GET is suitable for simple data retrieval as described in REST.
If an HTTP client sets a timeout of 10 seconds, what happens if the server takes 15 seconds to respond?
Explanation: A client-side timeout means the client stops waiting and typically ends the request after the specified period, regardless of the server's actions. The server does not control the timeout; also, no automatic retry or forced server error is standard. The most accurate behavior is the client stopping at its own timeout.
What is a common reason for implementing pagination in API responses when listing many items?
Explanation: Pagination divides large result sets into smaller chunks, which helps manage memory and network usage, and improves request performance. It is not for hiding data or altering verbs and has no direct connection with managing status codes.
Which HTTP status code indicates that the client's request was successfully received and processed?
Explanation: A 200 status code signals a successful HTTP request. 201 means 'created' and is specific to resource creation, 301 is a permanent redirect, and 400 denotes a bad request. For a general successful operation, 200 is correct.
Which statement best describes an idempotent HTTP method?
Explanation: An idempotent method maintains the same effect no matter how often it is performed with the same input. Idempotency is unrelated to encryption, server error handling, or response compression, which are separate concepts.
Why should automatic retries be limited when receiving an HTTP 500 status code?
Explanation: Excessive retries on server error responses like 500 can worsen server issues by increasing load. 500 indicates a temporary server error, not a permanent one, and is not caused by client mistakes. Saving bandwidth is a minor consideration compared to protecting server resources.
Which scenario most appropriately uses the 201 HTTP status code?
Explanation: 201 is used when a new resource, like a user account, is created successfully. Fetching data typically uses 200, deleting might use 204, and updating a missing resource could result in 404 or 400. Only the creation scenario matches 201.
If you send multiple HTTP DELETE requests for the same resource, what should a correctly implemented RESTful API do?
Explanation: DELETE should be idempotent, so repeated requests have the same effect as a single one, usually responding with success even if the resource is gone. Deletes are not repeated, failures are not expected, and 201 is reserved for creation, not deletion.
Which pair of URL query parameters is commonly used to implement pagination in REST APIs?
Explanation: 'limit' specifies the number of items to return, and 'offset' specifies how many to skip, making them common for pagination. 'retry' and 'timeout' relate to error handling, 'query' and 'filter' relate to searching, and 'start' and 'stop' are less standard.
What is a typical header a REST API may use to indicate more pages are available?
Explanation: The Link header can provide next, previous, and other pagination-related URLs. X-Rate-Limit relates to throttling, ETag to caching and versioning, and Content-Length shows response size. Only Link is typical for pagination information.
Which HTTP method should not change the server state and is considered 'safe'?
Explanation: GET is safe and used only for retrieving data, without altering resources. POST, PATCH, and DELETE are designed to create, modify, or remove data, making them not 'safe' in HTTP’s terminology.
Which status code class do codes beginning with '4' (e.g., 404) belong to in HTTP?
Explanation: Codes starting with '4' are Client Error codes, meaning the error originated from the client's side. 'Informational' covers 1xx, 'Server Error' is 5xx, and 'Redirect' is for 3xx. Only 'Client Error' matches 4xx codes like 404.
Which HTTP status code is commonly considered safe to retry automatically?
Explanation: 502 Bad Gateway indicates a temporary issue with upstream servers and is often recoverable by retrying. 401 is an authentication error, 400 is a client-side error, and 201 is a success code indicating resource creation, so only 502 is retryable.
Which HTTP method is defined as both idempotent and safe?
Explanation: GET is both idempotent (repeating the request does not change the resource) and safe (it does not modify server state). PUT is idempotent but not safe, POST is neither, and PATCH is neither guaranteed safe nor idempotent.
When a client-side timeout occurs before the server responds, what is the best practice for the client?
Explanation: Retrying with exponential backoff (increasing wait times) helps avoid overwhelming the server and increases the chance of eventual success. Waiting indefinitely is not practical, switching protocols is not standard upon timeouts, and sending PATCH is unrelated.