Skip to content

Home > @opengovsg/rate-limit > LocalRateLimiter

LocalRateLimiter interface ​

A rate limiter keyed by actor and resource, for identified traffic. Obtain one via createLocalRateLimiter().

Signature:

typescript
export interface LocalRateLimiter

Methods ​

MethodDescription
check(args)

Consume from the allowance of actor on resource.

resource must be a controlled, safe, normalized route identity. Raw URLs are not suitable, as they make every parameter value its own bucket, which fragments the actor's quota and grows store key cardinality without bound. : is replaced with |-| to avoid colliding with the common namespace:subkey scheme, and | is replaced with || to avoid colliding with that replacement.

actor is caller-defined: a user ID, an API-key ID, or a client IP for anonymous traffic.

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

Throws RateLimitExceededError when the allowance is exhausted.