You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using axios.create() to create new instances of axios and thereby avoid adding interceptors to the global axios object. Firstly, let me say that it is awesome that you've exposed an API that allows this! Unfortunately, I had to spend a bit too much time discovering that axios.create() does not return a function, like require('axios') does.
This means that I cannot use the following way of invoking my axios instance:
varaxios=require('axios');varinstance=axios.create({foo: 123});instance({//this needs to be `instance.request` in order for it to workurl: '...',}).then(handler).catch(errHandler);
I am fine using instance.request instead of just instance, but it is inconsistent with the API exposed by the default axios object.
Solutions:
Modify axios.create to return a bound function call to Axios.prototype.request() instead of the plain axios instance object. This is the same thing that is exported by axios.js.
If you're not up for doing that, maybe we can just document this behavior in the README under axios.create.
I would love to implement either solution: just let me know which you prefer (if any).
The text was updated successfully, but these errors were encountered:
I don't like the idea of creating an instance of something and then using that instance as a function, but I would be happy to merge a PR that updates the README. Thank you!
I am using
axios.create()
to create new instances of axios and thereby avoid adding interceptors to the global axios object. Firstly, let me say that it is awesome that you've exposed an API that allows this! Unfortunately, I had to spend a bit too much time discovering thataxios.create()
does not return a function, likerequire('axios')
does.This means that I cannot use the following way of invoking my axios instance:
I am fine using
instance.request
instead of justinstance
, but it is inconsistent with the API exposed by the default axios object.Solutions:
axios.create
to return a bound function call toAxios.prototype.request()
instead of the plain axios instance object. This is the same thing that is exported by axios.js.axios.create
.I would love to implement either solution: just let me know which you prefer (if any).
The text was updated successfully, but these errors were encountered: