[]previous and next page

RateLimiter

A token-bucket rate limiter.

A token-bucket rate limiter.

Import#

ts
import type { RateLimiter } from "@shadow-js/dusk/server";

Signature#

ts
interface RateLimiter {
  /** Takes `cost` tokens from the bucket of `key`. */
  check(key: string, cost?: number): Promise<RateLimitDecision>;
  /** Middleware that answers 429 with `Retry-After` when the bucket is empty. */
  middleware(options?: RateLimitMiddlewareOptions): Middleware;
  readonly spec: BucketSpec;
}

Members#

Name Type Description
check check(key: string, cost?: number): Promise<RateLimitDecision> Takes cost tokens from the bucket of key.
middleware middleware(options?: RateLimitMiddlewareOptions): Middleware Middleware that answers 429 with Retry-After when the bucket is empty.
spec readonly spec: BucketSpec