Challenge your understanding of HTTP and REST basics, including request/response flow, status codes, idempotency, pagination, and retry strategies. This quiz helps you assess core concepts in building and maintaining robust RESTful APIs.
Which HTTP method is generally used to retrieve data from a server without modifying any resources, such as fetching user details?
Explanation: GET is used to request and retrieve data from the server without changing it. POST is intended for creating new resources, which alters the state of the server. DELETE removes a resource, and PATCH updates part of a resource. Only GET guarantees no modifications are made.
What does an HTTP status code of 201 indicate after a client creates a new object?
Explanation: The 201 Created status code signals that a resource has been successfully created as a result of the request. 'Moved Permanently' (301) relates to redirection, 'Accepted' (202) means the request was received but not yet acted upon, and 'No Content' (204) indicates success with no message body.
Which HTTP method is designed to be idempotent, meaning making the same request multiple times produces the same result, such as multiple deletions of an item?
Explanation: DELETE is idempotent because deleting the same resource multiple times has the same effect as deleting it once. POST is not idempotent, as it usually creates a new resource each time. CONNECT and TRACE are specialized methods not typically associated with resource manipulation.
In a typical HTTP request/response flow, where are request headers located, and what purpose do they serve?
Explanation: Request headers appear at the beginning of an HTTP request and carry important metadata. They are not located in the body, nor are they part of the end of the response or just after the status code. Response headers, not request headers, are sent back after the status code.
If a client requests a non-existent resource, which HTTP status code should the server return?
Explanation: The 404 Not Found code tells the client that the requested resource does not exist. 200 OK means the request succeeded, which is inaccurate here. 201 Created is for successful resource creation, and 500 Internal Error signals a server malfunction, not a missing resource.
Which approach is commonly used in REST APIs to provide pagination when returning large data sets, such as a list of products?
Explanation: Adding 'limit' and 'offset' to the query string enables pagination, returning only a subset of data per request. Sending all results at once is inefficient and impractical for large datasets. Changing the HTTP method or using binary blobs are not relevant or standard for API pagination.
When a server responds with a 429 Too Many Requests status code, what is a recommended next step for the client?
Explanation: A 429 status means the client should slow down; implementing a delay or exponential backoff helps avoid further rate limiting. Repeated immediate retries may worsen the problem, and changing the method or ignoring the response doesn't resolve excessive requests.
Which HTTP method is considered 'safe,' meaning it should only retrieve data and not cause any changes on the server, even if used many times?
Explanation: GET is classified as a safe method as it solely fetches data without any side effects. PUT and DELETE can modify or remove resources, and POST usually creates or processes data, making them not safe methods.
If an API responds with a 204 No Content status after a DELETE request, what does this convey to the client?
Explanation: A 204 No Content status indicates a successful request with no further content to return, which is typical after deleting a resource. It's not an error, it doesn't suggest a partial deletion, and it doesn't relate to resource creation.
Which HTTP header can be used by the server to tell clients how long a response can be cached, for example when serving static images?
Explanation: Cache-Control dictates caching policies, such as how long a response can be stored by the client. Allow specifies supported HTTP methods, Referer shows the origin of the request, and Content-Disposition manages how content should be presented or downloaded, unrelated to caching.