Replies: 1 comment 4 replies
-
|
Yes, TanStack Pacer supports this. You can use a single rate limiter instance and call it from different functions: import { RateLimiter } from "@tanstack/pacer";
const apiLimiter = new RateLimiter({
limit: 10,
interval: 1000 // 10 requests per second
});
// All CRUD operations share the same limiter
async function createItem(data) {
await apiLimiter.maybeExecute(() => fetch("/api/items", { method: "POST", body: JSON.stringify(data) }));
}
async function getItems() {
await apiLimiter.maybeExecute(() => fetch("/api/items"));
}
async function updateItem(id, data) {
await apiLimiter.maybeExecute(() => fetch("/api/items/" + id, { method: "PUT", body: JSON.stringify(data) }));
}
async function deleteItem(id) {
await apiLimiter.maybeExecute(() => fetch("/api/items/" + id, { method: "DELETE" }));
}The rate limiter tracks all calls regardless of which function triggered them. You can also use the queue-based approach with |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Usually when an API server enforces rate limits, all api endpoints (CRUD) are affected.
Can we have a single rate limiter to track all CRUD api calls?
Beta Was this translation helpful? Give feedback.
All reactions