0
0
Rest APIprogramming~10 mins

Rate limit error responses in Rest API - Interactive Code Practice

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

Complete the code to set the HTTP status code for a rate limit error response.

Rest API
response.status_code = [1]
Drag options to blanks, or click blank then click option'
A500
B404
C200
D429
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 which means Not Found.
Using 500 which means server error.
Using 200 which means success.
2fill in blank
medium

Complete the code to add a 'Retry-After' header indicating how many seconds to wait before retrying.

Rest API
response.headers['Retry-After'] = [1]
Drag options to blanks, or click blank then click option'
A'sixty'
B'60 minutes'
C'60'
D'one hour'
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'sixty' or 'one hour' instead of seconds.
Using '60 minutes' which is not a valid format.
3fill in blank
hard

Fix the error in the code to return a JSON response with the correct status code for rate limiting.

Rest API
return JsonResponse({'error': 'Rate limit exceeded'}, status=[1])
Drag options to blanks, or click blank then click option'
A429
B404
C500
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 which means Not Found.
Using 500 which means server error.
Using 200 which means success.
4fill in blank
hard

Fill both blanks to create a dictionary with the error message and the retry time in seconds.

Rest API
error_response = {'message': [1], 'retry_after': [2]
Drag options to blanks, or click blank then click option'
A'Rate limit exceeded'
B'Please wait before retrying'
C60
D120
Attempts:
3 left
💡 Hint
Common Mistakes
Using a message that is not clear about rate limiting.
Using retry_after as a string instead of a number.
5fill in blank
hard

Fill all three blanks to create a full HTTP response with status code, headers, and JSON body for rate limiting.

Rest API
return Response([1], status=[2], headers=[3])
Drag options to blanks, or click blank then click option'
A{'error': 'Too many requests'}
B429
C{'Retry-After': '60'}
D{'message': 'Try again later'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong status codes like 404 or 200.
Missing the 'Retry-After' header.
Using incorrect body format.