Is there a way to disable rate limiting on every/individual routes in Laravel?
I'm trying to test an endpoint that receives a lot of requests, but randomly Laravel will start responding with { status: 429, responseText: 'Too Many Attempts.' }
for a few hundred requests which makes testing a huge pain.
A: For disabling the rate limiter in Laravel, first go to the app/Http/Kernel. php. There you will find the default throttle limit defined by Laravel for all api routes. Just comment out that code to disable it completely.
Laravel API rate limiting 100 requests per minute.
There are two ways to implement rate limiting with Laravel: Using the Rate Limiter Middleware: to rate limiting incoming HTTP requests before reaching the controller. Using the Rate Limiting abstraction: to interact more finely with the rate limiter at the controller level.
Laravel includes a simple to use rate limiting abstraction which, in conjunction with your application's cache, provides an easy way to limit any action during a specified window of time. If you are interested in rate limiting incoming HTTP requests, please consult the rate limiter middleware documentation.
In app/Http/Kernel.php
Laravel has a default throttle limit for all api routes.
protected $middlewareGroups = [ ... 'api' => [ 'throttle:60,1', ], ];
Comment or increase it.
You can actually disable only a certain middleware in tests.
use Illuminate\Routing\Middleware\ThrottleRequests;
class YourTest extends TestCase
{
protected function setUp()
{
parent::setUp();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
...
}
Assuming you are using the API routes then you can change the throttle in app/Http/Kernel.php or take it off entirely. If you need to throttle for the other routes you can register the middleware for them separately.
(example below: throttle - 60 attempts then locked out for 1 minute)
'api' => [
'throttle:60,1',
'bindings',
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With