Skip to content

Home > @opengovsg/rate-limit > RateLimiter

RateLimiter interface ​

A rate limiter. Obtain one via createRateLimiter(), createGlobalRateLimiter() or createLocalRateLimiter().

Signature:

typescript
export interface RateLimiter

Methods ​

MethodDescription
check(args)

Consume one point from key's allowance.

Resolves with a RateLimitInfo snapshot when within limits. Throws RateLimitExceededError when the allowance is exhausted. Any other error is reported via logger.error and rethrown as-is, so the caller decides between failing open and failing closed.

Pass a request-scoped logger to attach request identity to anything this call may log. Omit it to fall back to the factory logger.