rogervila/lumen-rate-limiting
Add rate limiting to Lumen applications with this lightweight middleware. Define request limits, protect API routes from abuse, and customize throttled responses with a simple setup.
composer require rogervila/lumen-rate-limiting:^2.0. Version 2.x targets Lumen 11; if you're still on Lumen 9/10, pin ^1.2 — the major bump is a dependency-constraint break, not an API redesign, so most 1.x usage examples still apply.bootstrap/app.php:
$app->register(Rogervila\LumenRateLimiting\RateLimitingServiceProvider::class);
config/ and add $app->configure('rate-limiting'); (or whatever the package names it) in bootstrap/app.php before the provider registration.CACHE_DRIVER=array works for tests but resets every request — production needs redis, memcached, database, or file with a shared volume.routes/web.php and hit it in a loop with curl to confirm you get a 429 after N requests.$router->group(['middleware' => 'throttle:60,1'], function () use ($router) {
$router->post('/login', 'AuthController@login');
});
Register the short alias in bootstrap/app.php via $app->routeMiddleware([...]) if the package exposes an alias; otherwise pass the FQCN.Retry-After plus a JSON body matching your API's error envelope — clients and HTTP caches both use that header.Cache::flush() in setUp() and Laravel's time-travel helpers to assert the window actually decays, rather than just asserting the 429. A limiter that never resets is the most common silent bug.illuminate/* constraints?" Run composer why-not rogervila/lumen-rate-limiting 2.0.0 before assuming the code needs changes. Expect to also bump laravel/lumen-framework to ^11.0.APP_ENV=local with CACHE_DRIVER=array, every request starts with an empty counter — limits never trigger and you'll wrongly conclude the middleware isn't registered. Test against Redis or at least file.TrustProxies-equivalent middleware isn't configured, keys collapse to the proxy IP and one noisy client locks out everyone. Lumen requires this to be set up manually.route:list showing the resolved stack. Debug by dumping inside the middleware or temporarily logging the computed cache key — that key tells you instantly whether you're keying by IP, user, or route.$app->configure(...) silently falls back to package defaults, so limits appear to ignore your config file. Verify with config('...') in tinker/a scratch route.artisan cache:clear on Redis nukes everything else too).composer.json and note the Lumen 11 requirement in your upgrade notes; this package moves in lockstep with Lumen majors and won't backport.How can I help you explore Laravel packages today?