all repos — kitten @ db843bde0743c7d7e04c0d8aae914104ce2ccc65

pkgs/ratelimit/README.md (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
# @purrkit/ratelimit

this package provides a rate limiting manager for [@purrkit/rest](https://npmx.dev/@purrkit/rest)

## example usage

```ts
import { RESTClient } from "@purrkit/rest";
import { RateLimitManager } from "@purrkit/ratelimit";

const limiter = new RateLimitManager({
	onDebug: (msg, data) => {
		console.log(`[REST] ${msg}`, data || "");
	},
	onRateLimit: ({ routeId, global, delayMs, bucketHash }) => {
		const type = global ? "GLOBAL" : "LOCAL";
		console.warn(
			`[RateLimit] Hit ${type} limit on ${routeId}. Pausing for ${delayMs}ms (bucket: ${bucketHash})`,
		);
	},
});

const rest = RESTClient({
	token: "...",
	fetch: limiter.fetch,
});
```

## copying

this project is licensed under the european union public license (eupl) v1.2.
you can find the full license text either [here][LISC] or on the official
[eupl website][EU], which also contains translations of the license in various
languages.

<!-- links -->

[LISC]: ./LICENSE
[EU]: https://interoperable-europe.ec.europa.eu/collection/eupl/eupl-text-eupl-12