Laravel: different api speed limits for different paths

I need to configure different speed limits for different paths. Game example:

For the / users path, I want to have a speed limit of 60 requests per minute, and for the / stats path I want the speed limit to be only 5 requests per minute.

I tried with a follow up approach

Route::group(['middleware' => ['auth', 'throttle:60']], function(){ Route::get('users', ' User@list '); }); Route::group(['middleware' => ['auth', 'throttle:5']], function(){ Route::get('stats', ' User@stats '); }); 

Somehow the last bet limit is applied. However, when performing requests to users' paths, the X-Rate-Limit-Limit header is set to 60, but when it reaches the 6th request, it generates the error "Too many requests."

+5
source share
1 answer

You can try to comment on the default bid line 40 Kernel.php , because you specify it in each group of middleware to avoid conflict.

You can also modify the middleware to include a second parameter on how long the wait period will last until the next incoming request (for example, throttle:60,1 )

+2
source

Source: https://habr.com/ru/post/1267317/


All Articles