0
0
Rest APIprogramming~20 mins

Rate limit error responses in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rate Limit Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:00remaining
What is the HTTP status code returned for a rate limit error?
When a REST API enforces rate limiting and a client exceeds the allowed number of requests, what HTTP status code should the server return?
A200 OK
B429 Too Many Requests
C500 Internal Server Error
D403 Forbidden
Attempts:
2 left
💡 Hint
Think about the standard HTTP status code specifically designed for rate limiting.
Predict Output
intermediate
1:00remaining
What header informs the client about when to retry after rate limiting?
Which HTTP response header tells the client how many seconds to wait before making another request after hitting a rate limit?
ARetry-After
BX-RateLimit-Reset
CContent-Type
DAuthorization
Attempts:
2 left
💡 Hint
This header is part of the HTTP standard and indicates wait time.
🧠 Conceptual
advanced
1:30remaining
Why is it important to include rate limit headers in error responses?
Why should a REST API include headers like Retry-After or X-RateLimit-Remaining in responses when rate limiting is applied?
ATo help clients understand when they can safely retry requests and avoid unnecessary failures
BTo increase server load by making clients send more requests
CTo hide the rate limit policy from clients
DTo make responses larger for better network utilization
Attempts:
2 left
💡 Hint
Think about how clients can behave better with more information.
Predict Output
advanced
1:30remaining
What is the typical JSON body content of a rate limit error response?
Given a REST API returns a 429 status code, which JSON response body best informs the client about the rate limit error?
A{"error": "Invalid API key"}
B{"message": "Success", "data": []}
C{"status": 200, "error": null}
D{"error": "Rate limit exceeded", "retry_after": 30}
Attempts:
2 left
💡 Hint
Look for a message about rate limiting and a retry time.
🔧 Debug
expert
2:00remaining
Identify the error in this rate limit middleware code snippet
This code snippet is intended to return a 429 error with a Retry-After header when the client exceeds the rate limit. What is the error?
Rest API
function rateLimit(req, res, next) {
  if (req.requests > 100) {
    res.status(429);
    res.set('Retry-After', '60');
    res.send({ error: 'Rate limit exceeded', retry_after: 60 });
    return;
  }
  next();
}
AThe status code 429 is incorrect for rate limiting
BThe Retry-After header value must be a date string, not a number
CThe middleware calls next() even after sending a response, causing headers to be sent twice
DThe error message should be sent as plain text, not JSON
Attempts:
2 left
💡 Hint
Think about what happens after res.send() is called in middleware.