
Research
/Security News
Popular Go Decimal Library Targeted by Long-Running Typosquat with DNS Backdoor
A long-running Go typosquat impersonated the popular shopspring/decimal library and used DNS TXT records to execute commands.
@jutech-devs/api-rate-limiter
Advanced tools
Advanced API rate limiting SDK with multiple strategies and React hooks
Advanced API rate limiting SDK with multiple strategies and React hooks support.
npm install @jutech-devs/api-rate-limiter
# or
yarn add @jutech-devs/api-rate-limiter
import { useRateLimiter } from '@jutech-devs/api-rate-limiter';
function APIComponent() {
const { makeRequest, state, canMakeRequest } = useRateLimiter({
maxRequests: 10,
windowMs: 60000, // 1 minute
strategy: 'sliding-window'
});
const fetchData = async () => {
try {
const result = await makeRequest(() =>
fetch('/api/data').then(res => res.json())
);
console.log('Data:', result);
} catch (error) {
console.error('Rate limited:', error.message);
}
};
return (
<div>
<p>Remaining requests: {state.remaining}</p>
<p>Reset time: {new Date(state.resetTime).toLocaleTimeString()}</p>
<button onClick={fetchData} disabled={!canMakeRequest()}>
Fetch Data
</button>
</div>
);
}
import { RateLimiter } from '@jutech-devs/api-rate-limiter';
const limiter = new RateLimiter({
maxRequests: 100,
windowMs: 60000,
strategy: 'token-bucket'
});
async function makeAPICall() {
try {
const result = await limiter.makeRequest(() =>
fetch('/api/endpoint').then(res => res.json())
);
return result;
} catch (error) {
if (error.name === 'RateLimitError') {
console.log(`Rate limited. Retry after ${error.retryAfter}ms`);
}
throw error;
}
}
Maintains a rolling window of requests. Most accurate but uses more memory.
const { makeRequest } = useRateLimiter({
maxRequests: 100,
windowMs: 60000,
strategy: 'sliding-window'
});
Resets the counter at fixed intervals. Memory efficient but can allow bursts.
const { makeRequest } = useRateLimiter({
maxRequests: 100,
windowMs: 60000,
strategy: 'fixed-window'
});
Allows burst requests up to bucket capacity. Smooth rate limiting.
const { makeRequest } = useRateLimiter({
maxRequests: 100,
windowMs: 60000,
strategy: 'token-bucket'
});
import { useRateLimitedAPI } from '@jutech-devs/api-rate-limiter';
function APIComponent() {
const { makeAPIRequest, state } = useRateLimitedAPI({
maxRequests: 10,
windowMs: 60000
});
const fetchWithRetry = async () => {
try {
const result = await makeAPIRequest(
() => fetch('/api/data').then(res => res.json()),
{
maxRetries: 3,
retryDelay: 1000,
exponentialBackoff: true
}
);
console.log('Success:', result);
} catch (error) {
console.error('Failed after retries:', error);
}
};
return (
<div>
<button onClick={fetchWithRetry}>Fetch with Auto-Retry</button>
<p>Status: {state.isLimited ? 'Rate Limited' : 'Available'}</p>
</div>
);
}
import { useBatchRateLimiter } from '@jutech-devs/api-rate-limiter';
function BatchProcessor() {
const { addToQueue, state, queueLength } = useBatchRateLimiter({
maxRequests: 5,
windowMs: 10000
});
const processBatch = async () => {
const requests = [
() => fetch('/api/item/1').then(res => res.json()),
() => fetch('/api/item/2').then(res => res.json()),
() => fetch('/api/item/3').then(res => res.json()),
];
const results = await Promise.all(
requests.map(req => addToQueue(req))
);
console.log('Batch results:', results);
};
return (
<div>
<button onClick={processBatch}>Process Batch</button>
<p>Queue length: {queueLength}</p>
<p>Remaining: {state.remaining}</p>
</div>
);
}
import { useMultiRateLimiter } from '@jutech-devs/api-rate-limiter';
function MultiAPIComponent() {
const { makeRequest, getAllStates } = useMultiRateLimiter({
github: { maxRequests: 60, windowMs: 3600000 }, // GitHub API
twitter: { maxRequests: 300, windowMs: 900000 }, // Twitter API
internal: { maxRequests: 1000, windowMs: 60000 } // Internal API
});
const fetchGitHubData = () =>
makeRequest('github', () =>
fetch('/api/github/user').then(res => res.json())
);
const fetchTwitterData = () =>
makeRequest('twitter', () =>
fetch('/api/twitter/tweets').then(res => res.json())
);
const states = getAllStates();
return (
<div>
<button onClick={fetchGitHubData}>
GitHub API (Remaining: {states.github?.remaining})
</button>
<button onClick={fetchTwitterData}>
Twitter API (Remaining: {states.twitter?.remaining})
</button>
</div>
);
}
interface RateLimiterConfig {
maxRequests: number; // Maximum requests per window
windowMs: number; // Time window in milliseconds
strategy: 'sliding-window' | 'fixed-window' | 'token-bucket';
retryAfter?: number; // Default retry delay
skipSuccessfulRequests?: boolean; // Don't count successful requests
skipFailedRequests?: boolean; // Don't count failed requests
}
interface RateLimiterState {
remaining: number; // Requests remaining in current window
resetTime: number; // When the window resets (timestamp)
isLimited: boolean; // Whether currently rate limited
retryAfter: number; // Milliseconds to wait before retry
totalRequests: number; // Total requests made in current window
}
useRateLimiter(config, callbacks)Basic rate limiting hook with full control.
useRateLimitedAPI(config)API requests with automatic retry logic.
useBatchRateLimiter(config)Queue and process requests in batches.
useMultiRateLimiter(configs)Manage multiple rate limiters for different APIs.
const { makeRequest } = useRateLimiter(
{ maxRequests: 10, windowMs: 60000 },
{
onRateLimit: (retryAfter) => {
console.log(`Rate limited! Retry after ${retryAfter}ms`);
},
onReset: () => {
console.log('Rate limit window reset');
},
onRequest: (remaining) => {
console.log(`${remaining} requests remaining`);
}
}
);
import { RateLimitError } from '@jutech-devs/api-rate-limiter';
try {
await makeRequest(() => fetch('/api/data'));
} catch (error) {
if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after: ${error.retryAfter}ms`);
// Handle rate limit specifically
} else {
console.error('Other error:', error);
}
}
MIT © JuTech Devs
Contributions welcome! Please read our contributing guidelines.
For support, open an issue on GitHub or contact support@jutech-devs.com
FAQs
Advanced API rate limiting SDK with multiple strategies and React hooks
We found that @jutech-devs/api-rate-limiter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
A long-running Go typosquat impersonated the popular shopspring/decimal library and used DNS TXT records to execute commands.

Research
Active npm supply chain attack compromises @antv packages in a fast-moving malicious publish wave tied to Mini Shai-Hulud.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.