Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 850 Bytes

File metadata and controls

37 lines (25 loc) · 850 Bytes

Rate Limiting

The rate limiter provides a small request-throttling layer and a matching middleware.

Register the Provider

use Myxa\RateLimit\RateLimitServiceProvider;

$app->register(new RateLimitServiceProvider());

Use the Limiter

$limiter = $app->make(\Myxa\RateLimit\RateLimiter::class);
$result = $limiter->consume('login:127.0.0.1', 5, 60);

if (!$result->allowed) {
    // reject request
}

Route Middleware Example

use Myxa\Support\Facades\Route;

Route::get('/api/users', [UserController::class, 'index'])
    ->middleware(\Myxa\Middleware\RateLimitMiddleware::using(60, 60, 'api'));

Notes

  • the default store is filesystem-backed unless you bind another store
  • exceeded limits throw TooManyRequestsException
  • the default HTTP exception handler adds rate-limit headers automatically