Home > Mobile >  Laravel Throttle in API not behaving as expected
Laravel Throttle in API not behaving as expected

Time:09-11

I am using following line of code to throttle API requests

Route::post('webhook/update', [TaskController::class, 'update'])->middleware(['auth:sanctum', 'verified','throttle:10000,1']);

I have kept very high throttle value on purpose but I still get 429 - Too Many Requests sometimes, the reason is unknown to me. Even though we are not hitting the API so many times in a min, it still throws back 429.

CodePudding user response:

There is another place where Laravel adds throttling to your API requests. You can find it in the App\Http\Kernel class under the $middlewareGroups property.

Just comment it out from that file to prevent all your API requests from using the default Laravel API throttling.

CodePudding user response:

just increase the throttle limit define in app\Http\Kernel.php under middlewareGroups

the throttle middleware define in routes will only work if its less than the throttle value define on Kernel. the value on Kernel is the maximum value you can set on routes middleware

so if your Kernel throttle is 60 per minute, the throttle you'll define in routes will only work if its less than 60,

so if you want this 'throttle:10000,1' to work in api routes middleware, you have to increase the api throttle in Kernel to 10000 or more

  • Related