Back-End Development RESTful API Design and Development 2 — Questions and Answers
Question 1: What is the primary purpose of API rate limiting?
- To speed up API responses
- To restrict the number of requests a client can make in a given time window (Correct answer)
- To enforce REST constraints
- To validate API payloads
Correct answer: To restrict the number of requests a client can make in a given time window
Rate limiting protects the server from abuse and ensures fair usage by capping how many requests a client can make within a time period.
Question 2: Which tool is most commonly used to document REST APIs using the OpenAPI Specification?
- Postman Collections
- Swagger UI (Correct answer)
- GraphQL Playground
- Insomnia REST
Correct answer: Swagger UI
Swagger UI renders OpenAPI Specification files into interactive, browser-based API documentation.
Question 3: What does the HTTP 422 Unprocessable Entity status code mean in a REST API context?
- The resource was not found
- The server understood the request but could not process it due to semantic errors (Correct answer)
- The client is unauthenticated
- The server encountered an internal error
Correct answer: The server understood the request but could not process it due to semantic errors
HTTP 422 indicates the request is well-formed but contains semantic errors, such as validation failures on the payload.
Question 4: Which approach is considered best practice when returning collections in a REST API?
- Always return all records
- Return paginated results with metadata (Correct answer)
- Return only the first 10 records by default with no indication
- Require the client to specify an exact count
Correct answer: Return paginated results with metadata
Paginated responses with metadata (total count, page, limit) allow clients to efficiently navigate large datasets.
Question 5: Which HTTP method should be used for a partial update of a resource in a REST API?
- PUT
- POST
- PATCH (Correct answer)
- UPDATE
Correct answer: PATCH
PATCH is used for partial updates, sending only the fields that need to be changed rather than the full resource representation.
Question 6: What is the role of an API gateway in a back-end architecture?
- Directly querying the database on behalf of clients
- Acting as a single entry point that handles routing, auth, rate limiting, and load balancing (Correct answer)
- Replacing the need for a web server
- Generating API documentation automatically
Correct answer: Acting as a single entry point that handles routing, auth, rate limiting, and load balancing
An API gateway acts as a reverse proxy that consolidates cross-cutting concerns like authentication, rate limiting, and routing for multiple back-end services.
What is the primary purpose of API rate limiting?