Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Sharing the AxiosRateLimit instance between AxiosClient instances #75

Open
leorochael opened this issue Jul 24, 2024 · 0 comments · May be fixed by #76
Open

Enable Sharing the AxiosRateLimit instance between AxiosClient instances #75

leorochael opened this issue Jul 24, 2024 · 0 comments · May be fixed by #76

Comments

@leorochael
Copy link

leorochael commented Jul 24, 2024

Currently the axiosRateLimit function is the only export from the module, but I would like to be able to share rate-limiting between axios clients. That is, I'd like to be able to do something like this:

import axios from 'axios';
import rateLimit, { AxiosRateLimiter } from 'axios-rate-limit'

const limiter = AxiosRateLimiter( { maxRequests: 2, perMilliseconds: 1000, maxRPS: 2 } );

const sheet1 = rateLimit(axios.create({ baseURL: `${SHEETS_API_BASE_URL}/${spreadsheetId1}` }), { rateLimiter: limiter});
const sheet2 = rateLimit(axios.create({ baseURL: `${SHEETS_API_BASE_URL}/${spreadsheetId2}` }), { rateLimiter: limiter}); 

So that both sheet1 and sheet2 are rate-limited as if they were a single rate limited axios client. I.e. if two requests are done in the same second on client1, then a third request in the same second for client2 would be rate-limited into the next second.

From what I can see in the code, it's almost ready for that, as the axios parameter in the constructor for AxiosRateLimit is only used for the .enable() call, and in there it's only used to .use() the interceptors. And though it stores the return values of the .use() calls, it doesn't actually do anything with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant