0
0
Rest APIprogramming~10 mins

Why rate limiting protects services in Rest API - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a rate limit of 100 requests per minute.

Rest API
rate_limit = [1]  # requests per minute
Drag options to blanks, or click blank then click option'
A100
B1000
C10
D10000
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a very high number that doesn't protect the service.
2fill in blank
medium

Complete the code to check if the user has exceeded the rate limit.

Rest API
if requests_made > [1]:
    return '429 Too Many Requests'
Drag options to blanks, or click blank then click option'
A200
B500
C100
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using a lower or higher number than the set limit.
3fill in blank
hard

Fix the error in the code to correctly reset the request count after one minute.

Rest API
if time_since_last_reset > [1]:
    requests_made = 0
Drag options to blanks, or click blank then click option'
A30
B60
C120
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 30 or 120 seconds which do not match the rate limit period.
4fill in blank
hard

Fill both blanks to create a dictionary that tracks requests per user.

Rest API
user_requests = [1]  # dictionary to store counts
user_requests[user_id] = user_requests.get([2], 0) + 1
Drag options to blanks, or click blank then click option'
A{}
Buser_id
C[]
Drequests
Attempts:
3 left
💡 Hint
Common Mistakes
Using [] which creates a list, not a dictionary.
5fill in blank
hard

Fill all three blanks to implement a simple rate limiter function.

Rest API
def rate_limiter(user_id):
    if user_id not in [1]:
        [1][user_id] = 0
    [1][user_id] += 1
    if [1][user_id] > [2]:
        return '[3]'
    return 'OK'
Drag options to blanks, or click blank then click option'
Auser_requests
B100
C429 Too Many Requests
Drequests_count
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or incorrect status messages.