Controlling the view or API access
DoS attacks happen when a user maliciously accesses a web page or API multiple times to disrupt the traffic and make the resources inaccessible to others. Flask-Limiter
can provide an immediate solution by managing the number of access of a user to an API endpoint. First, install the Flask-Limiter
module using the following pip
command:
pip install flask-limiter
Also, install the module dependency for caching its configuration details to the Redis server:
pip install flask-limiter[redis]
Now, we can set up the module’s Limiter
class in the create_app()
factory method, like in the following snippet:
from flask_limiter import Limiter from flask_limiter.util import get_remote_address def create_app(config_file): app = Flask(__name__,template_folder= '../modules/pages', static_folder= '../modules/resources') … … … … …...