https://github.com/tanishqmanuja/axios-interceptor-suite
Axios Interceptor Suite is a collection of useful interceptors to make axios experience more pleasant when working with realtime API's.
https://github.com/tanishqmanuja/axios-interceptor-suite
axios interceptors rate-limit retry throttle
Last synced: 3 months ago
JSON representation
Axios Interceptor Suite is a collection of useful interceptors to make axios experience more pleasant when working with realtime API's.
- Host: GitHub
- URL: https://github.com/tanishqmanuja/axios-interceptor-suite
- Owner: tanishqmanuja
- License: mit
- Created: 2023-02-24T10:01:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-11T07:40:36.000Z (about 2 years ago)
- Last Synced: 2025-02-02T14:02:39.477Z (4 months ago)
- Topics: axios, interceptors, rate-limit, retry, throttle
- Language: TypeScript
- Homepage:
- Size: 150 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Axios Interceptor Suite
Axios Interceptor Suite is a collection of useful interceptors to make axios experience more pleasant when working with realtime API's.
## Installation
```sh
npm i @tqman/axios-interceptor-suite # npm
pnpm i @tqman/axios-interceptor-suite #pnpm
yarn add @tqman/axios-interceptor-suite # yarn
```## Usage
```ts
import axios from "axios"import { createRateLimitInterceptor,
createRetryInterceptor,
AxiosRateLimitRequestConfig,
AxiosRetryRequestConfig } from "@tqman/axios-interceptor-suite"// make your axios instance
const axiosInstance = axios.create() // ofcourse you will provide your base config// rate limit interceptor to send at most 6 requests per 2 seconds.
// overhead request will be delayed until next interval. Make sure originator of request is slower than the rate limit on average.
const { id, eject } = createRateLimitInterceptor(axiosInstance, {
count: 6;
interval: 2 * 1000;
})// retry interceptor to retry failed requests 2 times with delay of 1 second between each.
createRetryInterceptor(axiosInstance, {
count: 2;
delay: 1 * 1000; // delay can be function also: (retryCount) => (1 + 2 ** retryCount) * 1000
})// make you requests (with rate limit and retry)
axiosInstance.get("https://example.com")// make request without rate limit
axiosInstance.get("https://example.com", { bypassRateLimit: true } as AxiosRateLimitRequestConfig)// make request without retry on failure
axiosInstance.get("https://example.com", { retry: false } as AxiosRetryRequestConfig)// change retry config for specific request & disable rate limit
axiosInstance.get("https://example.com", { retry: { count: 5 }, bypassRateLimit: true } as AxiosRetryRequestConfig & AxiosRateLimitRequestConfig)// eject rate limit interceptor
eject()```