README
fetch-rate-limit-util
Handle fetch rate limits. Waits and retriy after rate limit rest time has reached
import { rateLimitHandler } from "fetch-rate-limit-util";
const response = rateLimitHandler( () => fetch(someURL));
API
Table of Contents
MIN_WAIT_MSECS
Minimum wait time in msecs.
Type: number
MAX_RETRIES
Max # of wait retries.
Type: number
defaultWaitDecide
Decide about the time to wait for a retry.
- only retry MAX_RETRIES times
- when waiting wait at least MIN_WAIT_MSECS
Parameters
millisecondsToWait
Integer ## of milliseconds to wait before retryrateLimitRemaining
Integer parsed from "x-ratelimit-remaining" headernthTry
Integer how often have we retried the request alreadyresponse
Object as returned from fetch
Returns Integer milliseconds to wait for next try or < 0 to deliver current response
rateLimitHandler
- See: https://auth0.com/docs/policies/rate-limit-policy
- See: https://developer.github.com/v3/#rate-limiting
- See: https://opensource.zalando.com/restful-api-guidelines/#153
Waits and retries after rate limit reset time has reached.
Parameters
fetcher
executes the fetch operationwaitDecide
(optional, defaultdefaultWaitDecide
)
install
With npm do:
npm install fetch-rate-limit-util
license
BSD-2-Clause