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

Possiblity to configure non global axios instance #100

Open
lbroman opened this issue Jun 20, 2021 · 0 comments
Open

Possiblity to configure non global axios instance #100

lbroman opened this issue Jun 20, 2021 · 0 comments

Comments

@lbroman
Copy link

lbroman commented Jun 20, 2021

To be able to have different axios configurations beyond axiosConfig (ie. interceptors) it should be possible to assign a an axios instance which will be used in place of the global axios, which remains the default.

One example of such use would be to use a separate logger and interceptors for logging WC requests.

`
let wcAxiosInstance = axios.create();

wcAxiosInstance.interceptors.request.use(req => {
    wcApiLogger.debug(`Request   ${req.method} ${req.url}`);
    wcApiLogger.debug(`Headers > ${JSON.stringify(req.headers)}`)
    return req;
});

wcAxiosInstance.interceptors.response.use(res => {
    wcApiLogger.debug(`Response ${res.config.method} ${res.config.url} ${res.status}`);
    wcApiLogger.debug(`Headers  < ${JSON.stringify(res.headers)}`)
    return res;
});

let wcApi = new WooCommerceRestApi({
url: ...,
consumerKey: ...,
consumerSecret: ...,
axiosInstance: wcAxiosInstance
});

`

lbroman added a commit to lbroman/woocommerce-rest-api-js-lib that referenced this issue Jun 20, 2021
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

No branches or pull requests

1 participant