0
0
Rest APIprogramming~20 mins

429 Too Many Requests in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
429 Too Many Requests Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the HTTP status code returned?
You have a REST API that limits clients to 5 requests per minute. If a client sends 6 requests quickly, what HTTP status code will the server return for the 6th request?
A429 Too Many Requests
B200 OK
C500 Internal Server Error
D403 Forbidden
Attempts:
2 left
💡 Hint
Think about what status code means the client sent too many requests in a short time.
🧠 Conceptual
intermediate
1:00remaining
Why use 429 Too Many Requests status code?
Which reason best explains why an API uses the 429 Too Many Requests status code?
ATo confirm the request was successful
BTo show the server encountered an unexpected error
CTo indicate the client is not authorized
DTo tell the client to slow down because it exceeded request limits
Attempts:
2 left
💡 Hint
Think about what happens when a client sends too many requests too fast.
🔧 Debug
advanced
2:00remaining
Identify the cause of unexpected 429 errors
A client reports receiving 429 Too Many Requests errors even though they send only 1 request per minute. What is the most likely cause?
AThe client is not authorized to access the API
BThe client is sending requests too slowly
CThe server's rate limit is set too low or misconfigured
DThe server is down and returning 429 by mistake
Attempts:
2 left
💡 Hint
Consider server settings that control request limits.
🚀 Application
advanced
1:30remaining
How to handle 429 errors in client code?
You receive a 429 Too Many Requests response from an API. What is the best way for your client application to handle this?
AWait for the time specified in the Retry-After header before retrying
BStop sending requests permanently
CImmediately retry the request without delay
DIgnore the error and continue sending requests
Attempts:
2 left
💡 Hint
Look for a header that tells you when to try again.
Predict Output
expert
3:00remaining
What is the output of this rate limiting code snippet?
Consider this Python Flask snippet implementing simple rate limiting. What will be the output on the 4th request from the same IP within 10 seconds?
Rest API
from flask import Flask, request, jsonify
import time

app = Flask(__name__)

request_times = {}

@app.route('/api')
def api():
    ip = request.remote_addr
    now = time.time()
    times = request_times.get(ip, [])
    # Remove timestamps older than 10 seconds
    times = [t for t in times if now - t < 10]
    if len(times) >= 3:
        return jsonify({'error': 'Too many requests'}), 429
    times.append(now)
    request_times[ip] = times
    return jsonify({'message': 'Success'})

# Simulate 4 requests from same IP quickly
ip = '192.168.1.1'
for i in range(4):
    request_times[ip] = [time.time() - 1, time.time() - 2, time.time() - 3]
    now = time.time()
    times = request_times.get(ip, [])
    times = [t for t in times if now - t < 10]
    if len(times) >= 3:
        print(429)
    else:
        times.append(now)
        request_times[ip] = times
        print(200)
A
200
200
200
200
B
200
200
200
429
C
429
429
429
429
D
200
429
429
429
Attempts:
2 left
💡 Hint
Check how many timestamps are kept and when 429 is returned.