Skip to content

Home > @opengovsg/rate-limit > LocalRateLimiter > check

LocalRateLimiter.check() method ​

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.

Signature:

typescript
check(args: {
        actor: string;
        resource: string;
        logger?: Logger;
    }): Promise<RateLimitInfo>;

Parameters ​

ParameterTypeDescription
args{ actor: string; resource: string; logger?: Logger; }

Returns:

Promise<RateLimitInfo>