0
0
Flaskframework~5 mins

Flask-Limiter for rate limiting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Flask-Limiter used for in a Flask application?
Flask-Limiter is used to control how many times a user or client can access certain routes in a Flask app within a set time. It helps prevent too many requests, protecting the app from overload or abuse.
Click to reveal answer
beginner
How do you apply a simple rate limit of 5 requests per minute to a Flask route using Flask-Limiter?
You decorate the route with @limiter.limit('5 per minute'). This tells Flask-Limiter to allow only 5 requests to that route every minute from the same client.
Click to reveal answer
intermediate
What is the default key used by Flask-Limiter to identify clients for rate limiting?
By default, Flask-Limiter uses the client's IP address to track and limit requests.
Click to reveal answer
advanced
How can you customize the key function in Flask-Limiter to use user ID instead of IP address?
You can pass a custom key function to Flask-Limiter that returns the user ID from the request context, so limits apply per user rather than per IP.
Click to reveal answer
beginner
What happens when a client exceeds the rate limit set by Flask-Limiter?
Flask-Limiter returns a 429 Too Many Requests HTTP response, telling the client to slow down and try again later.
Click to reveal answer
Which decorator applies a rate limit of 10 requests per hour to a Flask route?
A@limiter.rate('10/hour')
B@limiter.limit('hourly 10')
C@limiter.limit('10 per hour')
D@limit('10 requests per hour')
What default client identifier does Flask-Limiter use to track request counts?
AClient IP address
BUser agent string
CSession cookie
DRequest URL
What HTTP status code does Flask-Limiter return when a client exceeds the rate limit?
A429 Too Many Requests
B404 Not Found
C403 Forbidden
D500 Internal Server Error
How can you apply different rate limits to different routes in Flask-Limiter?
AUse different Flask apps for each route
BSet global limit once for all routes
CChange the IP address for each route
DUse @limiter.limit decorator with different limits on each route
Which of these is NOT a valid rate limit string for Flask-Limiter?
A'100 per day'
B'10 requests per minute'
C'20/hour'
D'5 per second'
Explain how Flask-Limiter helps protect a Flask app and how you set a basic rate limit on a route.
Think about stopping too many requests from one user.
You got /3 concepts.
    Describe how Flask-Limiter identifies clients by default and how you might change this behavior.
    Consider what makes each user unique.
    You got /2 concepts.