Test your knowledge of HTTP and REST basics with this quiz covering HTTP verbs, status codes, idempotency, pagination, and error handling. Ideal for those seeking a foundational understanding of RESTful APIs and HTTP operations.
Which HTTP verb should you use to retrieve data about a user profile without making any changes to it?
Explanation: GET is used to fetch data from a server without causing side effects. POST is for creating new resources, PUT is for updating existing resources, and DELETE removes resources. Only GET is designed specifically for safe data retrieval, making it the most appropriate choice.
What does the HTTP status code 404 indicate when accessing a RESTful API endpoint?
Explanation: A 404 status code means the requested resource could not be found on the server. 'Request successful' corresponds to 200, 'Internal server error' refers to 500, and 'Resource created' is indicated by 201. Therefore, only 'Resource not found' fits 404.
Which HTTP method is considered idempotent when updating a resource, meaning repeated identical requests have the same effect as one?
Explanation: PUT is idempotent because sending the same PUT request multiple times results in the resource being updated to the same state each time. POST is not idempotent as it usually creates new resources, CONNECT is used for opening a tunnel (not updating resources), and PATCH is generally not guaranteed to be idempotent. Only PUT fits this idempotency guarantee.
If you want to remove a specific item from a RESTful API, which HTTP verb should you use?
Explanation: DELETE is the correct verb for removing a resource in RESTful APIs. TRACE is used for diagnostic purposes, HEAD fetches only headers, and OPTIONS returns allowed HTTP methods. Only DELETE performs removal operations.
What HTTP status code is typically returned after successfully creating a new resource using a POST request?
Explanation: 201 indicates that a new resource has been created. 400 is for bad requests, 301 is for redirects, and 204 signals no content but does not indicate resource creation. Only 201 is correct for new resource creation acknowledgment.
Why do REST APIs commonly use pagination when returning large lists of data, such as a list of posts or products?
Explanation: Pagination reduces the amount of data sent in one response, making responses faster and more manageable. Hiding sensitive data and encrypting data involve security, not pagination. Increasing server errors is not an aim of pagination, making only 'To limit response size and improve performance' correct.
If a REST API returns a 500 status code after a request, what does this mean?
Explanation: A 500 status code signals an internal server error, usually indicating something went wrong on the server side. 'Redirected' corresponds to 3xx codes, 'Unauthorized' is 401, and 'Successful' is usually 200. Only the server error explanation fits code 500.
Which query parameters are commonly used for simple pagination in a RESTful API when fetching lists?
Explanation: The 'limit' and 'offset' parameters are standard for defining how many items to retrieve (limit) and where to start (offset). 'Code and type' or 'source and value' are not typical for pagination, and 'token and state' may be used in authentication or workflow, not pagination. 'Limit and offset' are the well-known standard.
If a client sends malformed or invalid input to a RESTful API, which HTTP status code should the server respond with?
Explanation: 400 indicates a bad request due to invalid or incorrect input from the client. 403 means forbidden access, 202 means the request has been accepted for processing, and 302 signals temporary resource redirection. 400 directly relates to client input errors.
When you want to update only a few fields of a resource in a RESTful API without replacing the entire resource, which HTTP verb should you use?
Explanation: PATCH is used to make partial updates, changing only specified fields. PUT replaces the entire resource with new data, GET is for retrieval with no changes, and CONNECT establishes tunnel connections, which are unrelated to updating resources. PATCH is the method designed for partial modifications.