twitchtv / node-apicalypse

The apicalypse query language client for nodejs
MIT License
86 stars 10 forks source link

add support for custom axios instance #20

Closed summerkiflain closed 3 months ago

summerkiflain commented 3 years ago

This is required if we want to add support for axios-retry, which requires axios instance to attach to, This PR will allow writing code like below:

const axios = require('axios').default
const axiosRetry = require('axios-retry').default
const apicalypse = require('apicalypse').default

const axiosInstance = axios.create()
axiosRetry(axiosInstance, {
  retries: 3,
  retryDelay: axiosRetry.exponentialDelay,
  retryCondition: error => {
    return axiosRetry.isNetworkOrIdempotentRequestError(error) ||
      error.response && error.response.status === 429
  }
});
const requestOptions = {
  queryMethod: 'body',
  method: 'post',
  baseURL: 'https://api.igdb.com/v4',
  responseType: 'json',
  timeout: 10000,
  axiosInstance,
}
const apicalypsePromise = apicalypse(requestOptions)
summerkiflain commented 3 years ago

@krazyjakee can you please merge this PR?, its very basic but very important for me.

summerkiflain commented 1 year ago

@husnjak can you please merge this PR?

summerkiflain commented 3 months ago

@krazyjakee Can you please review and merge this PR? This is very simple and basic change, it only allows passing in a custom axiosInstance to the apicalypse library, nothing changes in case if someone doesn't provide an axiosInstance. If you have any feedback I'll incorporate it.

krazyjakee commented 3 months ago

Thanks for this. Sorry for the 3 year delay.

summerkiflain commented 3 months ago

@krazyjakee Thanks dear 👍, Still appreciate it and thanks for publishing the updated version on npm also.