alepha@docs:~/docs/reference/primitives$
cat $throttle.md1 min read
#$throttle
#Import
typescript
1import { $throttle } from "alepha/datetime";
#Overview
Max calls per window. */ rate: number;
/**
- Window duration. */ per: DurationLike; }
/** Middleware that rate-controls handler execution using a token bucket.
Excess calls are delayed until capacity is available — never rejected.
Process-local (not distributed). Use $rateLimit for distributed rate limiting.
Use case: protect an external API from your own traffic.
typescript
1class PaymentController {2 charge = $action({3 use: [$throttle({ rate: 80, per: [1, "second"] })],4 handler: async ({ body }) => this.stripe.charges.create(body),5 });6}
#Options
| Option | Type | Required | Description |
|---|---|---|---|
rate |
number |
Yes | Max calls per window. |
per |
DurationLike |
Yes | Window duration. |