Repository navigation
RateLimitResult
Viames Marino edited this page Oct 19, 2026
·
1 revision
Pair\Api\RateLimitResult describes one decision returned by RateLimiter::attempt(). It does not perform a storage check itself.
| Field | Type | Meaning |
|---|---|---|
allowed |
bool |
Whether this request may continue. |
limit |
int |
Maximum hits allowed in the window. |
remaining |
int |
Hits still available after the decision. |
resetAt |
int |
Unix timestamp when the current window fully resets. |
retryAfter |
int |
Non-negative number of seconds before retrying a blocked request. |
driver |
string |
Storage backend that produced the result, normally file or redis. |
Emits X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. A blocked result also emits Retry-After. Call this before sending a response body.
use Pair\Api\ApiResponse;
use Pair\Api\RateLimiter;
$limiter = new RateLimiter(10, 60);
$result = $limiter->attempt('export:user:' . $userId);
$result->applyHeaders();
if (!$result->allowed) {
return ApiResponse::errorResponse('TOO_MANY_REQUESTS', [
'retryAfter' => $result->retryAfter,
'resetAt' => $result->resetAt,
]);
}applyHeaders() emits metadata only; the caller must stop work and return a response when allowed is false. ThrottleMiddleware already performs both steps for normal API requests.
See also: RateLimiter, ThrottleMiddleware, AuthAttemptLimiter, ApiErrorResponse.
Maintained by Viames Marino — VM Ingegneria · Professional enquiries
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4