What is throttling and how to implement it in Laravel?

Mahabubur Rahman
0



Throttling is a process to rate-limit requests from a particular IP. This can be used to prevent DDOS attacks as well. For throttling, Laravel provides a middleware that can be applied to routes and it can be added to the global middlewares list as well to execute that middleware for each request.

Here’s how you can we add it to a particular route:

Route::middleware('auth:api', 'throttle:30,1')->group(function () {
    Route::get('/user', function () {
        //
    });
});

This will enable the /user route to be accessed by a particular user from a particular IP only 30 times in a minute.

Post a Comment

0Comments
Post a Comment (0)