CSI RESTful API & Middleware Design 3 — Questions and Answers
Question 1: Which middleware pattern stores frequently accessed data closer to the consumer to reduce upstream API calls?
- Circuit breaker
- Caching proxy (Correct answer)
- Load balancer
- Service mesh
Correct answer: Caching proxy
A caching proxy intercepts requests and returns stored responses when valid, reducing latency and backend load.
Question 2: A REST API must expose the same resource in both JSON and XML formats based on client preference. Which mechanism should it use?
- Different URL endpoints for each format
- Query parameter ?format=xml
- HTTP Accept header content negotiation (Correct answer)
- Custom X-Format request header
Correct answer: HTTP Accept header content negotiation
Content negotiation via the Accept header is the HTTP-standard mechanism for clients to specify their preferred response format.
Question 3: What does the Richardson Maturity Model Level 3 (Hypermedia Controls) require of a REST API?
- Use of HTTPS for all endpoints
- Responses that include links guiding clients to available next actions (Correct answer)
- Support for all HTTP verbs on every resource
- JSON as the mandatory response format
Correct answer: Responses that include links guiding clients to available next actions
Level 3 (HATEOAS) requires responses to embed hypermedia links so clients can discover and navigate possible state transitions.
Question 4: In middleware design, a circuit breaker transitions to the 'open' state when:
- Network latency exceeds a threshold once
- A configurable number of consecutive failures occurs (Correct answer)
- The downstream service returns a 200 status
- CPU usage on the middleware host exceeds 80%
Correct answer: A configurable number of consecutive failures occurs
A circuit breaker opens after a defined failure threshold is reached, stopping further calls to the failing downstream service.
Question 5: Which REST API design practice best prevents over-fetching and under-fetching issues?
- Returning full resource representations always
- Implementing GraphQL instead of REST
- Supporting sparse fieldsets via query parameters like ?fields=id,name (Correct answer)
- Versioning every endpoint separately
Correct answer: Supporting sparse fieldsets via query parameters like ?fields=id,name
Sparse fieldsets allow clients to request only the specific fields they need, reducing payload size and avoiding under-fetching.
Question 6: When an API gateway performs request transformation, what is it doing?
- Encrypting the request payload end-to-end
- Modifying request structure or format before forwarding to backend services (Correct answer)
- Authenticating users against an identity provider
- Routing requests based on client geolocation
Correct answer: Modifying request structure or format before forwarding to backend services
Request transformation adapts incoming requests (e.g., headers, body format, parameters) to match what backend services expect.
Question 7: Which HTTP response status code indicates that a REST API resource has been permanently moved to a new URI?
- 302 Found
- 303 See Other
- 301 Moved Permanently (Correct answer)
- 307 Temporary Redirect
Correct answer: 301 Moved Permanently
301 Moved Permanently tells clients and search engines to update their references to the new URI for all future requests.
Which middleware pattern stores frequently accessed data closer to the consumer to reduce upstream API calls?