rogervila / lumen-rate-limiting
Lumen port of Laravel ThrottleRequests middleware
Installs: 36 550
Dependents: 1
Suggesters: 0
Security: 0
Stars: 16
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- laravel/lumen-framework: ^11.0
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-11-03 10:53:58 UTC
README
About
This package contains a Lumen port of Laravel's ThrottleRequests middleware.
Check the package version compatibility based on your Lumen's project version:
Install
- Require the package on your Lumen application
composer require rogervila/lumen-rate-limiting
- Make sure that
AppServiceProvider
andAuthServiceProvider
are uncommented onbootstrap/app.php
$app->register(App\Providers\AppServiceProvider::class); $app->register(App\Providers\AuthServiceProvider::class);
- Configure a rate limiter on the
AppServiceProvider
boot
method
/** * Configure global rate limiter * * @return void */ public function boot() { app(\Illuminate\Cache\RateLimiter::class)->for('global', function () { return \Illuminate\Cache\RateLimiting\Limit::perMinute(60)->by(request()->ip()); }); }
- Register the middleware on
bootstrap/app.php
$app->routeMiddleware([ 'throttle' => \LumenRateLimiting\ThrottleRequests::class, ]);
- Add the middleware to the global router group on
bootstrap/app.php
$app->router->group([ 'namespace' => 'App\Http\Controllers', 'middleware' => 'throttle:global', ], function ($router) { require __DIR__ . '/../routes/web.php'; });
The middleware can be placed on specific routes instead of globally, as defined on the official documentation.
License
This project is open-sourced software licensed under the MIT license.