question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios sub-instances

See original GitHub issue

This 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:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
mhelvenscommented, Sep 27, 2018

May I ask how this issue was resolved? Even with axios@0.19.0-beta.1 I am unable to do axios.create().create().

1reaction
emilyemorehousecommented, Apr 11, 2018

Closing, as this issue was resolved in #1395. 🙌

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found