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.
What does the HTTP status code 404 represent when a client sends a request for a resource?
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.
Which HTTP status code indicates a successful GET 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.
In RESTful API design, which URL format is preferred for accessing a list of books?
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.
What is the primary reason for implementing pagination in a RESTful API?
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.
Which HTTP method is typically considered idempotent, meaning repeated identical requests have the same effect as one request?
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.
After successfully creating a new user resource, which HTTP status code should the server return?
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.
Which HTTP method is considered 'safe' because it should not alter the state of the server?
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.
What status code should a server use to respond to a successful DELETE request with no content?
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.
Which HTTP method is mainly used to retrieve data from a server in a REST API?
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.
Which one of these is NOT a valid HTTP status code?
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.
Which query parameters are commonly used for pagination in RESTful APIs?
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.
When a client sends a malformed request to a REST API, which status code should be returned?
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.
When creating a resource with POST, which response header typically provides the URL of the new resource?
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.
Which of the following HTTP methods is both safe and idempotent?
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.
Which HTTP method is used to partially update a resource in a RESTful API?
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.
Which range of HTTP status codes represents client errors?
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.