Axios sub-instances
See original GitHub issueThis is a feature request for something I intuitively always thought Axios already had, until I actually tried to use it one day and it didn’t work.
// loggedAxios.js
export.defaults = require('axios').create()
loggedAxios.inerceptors.response.use(generateLogMessage)
// authorizedAxios.js
export.defaults = require('./loggedAxios').create({
headers: [{ authorization: `bearer ${token}` }]
})
// specificProject.js
const axios = require('./authorizedAxios').create({
baseUrl: `http://${specificProjectDomain}`
})
await axios.post('/endpoint') // logged, authorized, pointed at project host
So basically, I’m asking for axios.create().create()
to work, applying the expected order of precedence for options and interceptors (see also https://github.com/axios/axios/issues/993). This would be quite useful for large projects inside large companies, where a company-specific axios object could be prepared (logging, doing auth, etc.) that would still work as a drop-in replacement for vanilla axios.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:5 (1 by maintainers)
Top Results From Across the Web
The Axios Instance | Axios Docs
The Axios Instance. Creating an instance. You can create a new instance of axios with a custom config. axios.create([config]).
Read more >How to clone an axios instance - Stack Overflow
This is my setup to give an idea: Following is my global axiosClient(in file apiClient.js ), with some interceptors added(not shown in code)....
Read more >1st annual PKI research workshop proceedings
both primary trust relationships, which the node axio- matically trusts, and derived relationships, ... The first and third subcases are immediately.
Read more >deductive completeness and conditionalization - Project Euclid
H—• is the system of intuitionistic implication which may be axio- matized by: H—1. A-D ... Subcases 1-3: same as Case α, Subcases...
Read more >Refinitiv World-Check One API (2.51.0)
... Node + Unirest; Node + Axios; Csharp + Httpclient; Php + Curl ... cases listed in linkedCasesRequest as subcases which will be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
May I ask how this issue was resolved? Even with
axios@0.19.0-beta.1
I am unable to doaxios.create().create()
.Closing, as this issue was resolved in #1395. 🙌