Skip to content

Add Rate Limiting Support #290

@armanist

Description

@armanist

Introduce a first-class rate limiting feature in the Quantum PHP framework with fluent route-level configuration and pluggable backends. Developers should be able to control per-route request limits using a rateLimit() method, with support for file-based and Redis-based adapters.

Acceptance Criteria

  • Add rateLimit() method to the route definition chain:
Route::get('/api/posts', 'PostController@index')
    ->rateLimit(100, 60); // 100 requests per 60 seconds
  • Allow optional third parameter to define adapter (e.g., 'file' or 'redis'):
->rateLimit(100, 60, 'redis');
  • Create a RateLimitMiddleware that:

Resolves the adapter based on config or route input

Rejects request with 429 Too Many Requests if limit is exceeded

Define RateLimitAdapterInterface with:

public function hit(string $key, int $limit, int $interval): bool;
public function reset(string $key, int $count = 0): void;

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions