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

Allow axios.create(options) to be used recursively #2795

Merged
merged 3 commits into from Sep 5, 2021

Conversation

whitfin
Copy link
Contributor

@whitfin whitfin commented Mar 3, 2020

This PR tweaks axios.create(options) in such a way that it can be used recursively to extend clients. It's very useful in situations where you're connecting to multiple remotes which have some things in common, but not everything.

An easy example is when you are using several remotes which all use JSON response types. With this change, you can extend a single JSON client rather than redefining the responseType in every client.

const axios = require('axios');

const jsonClient = axios.create({
  responseType: 'json'
});

const serviceOne = jsonClient.create({
  baseURL: 'https://service.one/'
});

const serviceTwo = jsonClient.create({
  baseURL: 'https://service.two/'
});

Obviously the above example is small, but in an enterprise environment you may share many options between clients for different domain services. Given that the code change is fairly trivial, it seems like a good thing to support!

@github-actions
Copy link
Contributor

Hello! 👋 \n\nThis pull request is being automatically marked as stale because it has not been updated in a while. Please confirm that the issue is still present and reproducible. If no updates or new comments are received the pull request will be closed in a few days. \n\nThanks

@whitfin
Copy link
Contributor Author

whitfin commented Jun 22, 2020

Still very much a thing, just waiting for opinions :)

@jasonsaayman jasonsaayman merged commit 69d3cc4 into axios:master Sep 5, 2021
mbargiel pushed a commit to mbargiel/axios that referenced this pull request Jan 27, 2022
Co-authored-by: Jay <jasonsaayman@gmail.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants