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

Default method for an instance always overwritten by get #1121

Closed
Nilegfx opened this issue Oct 10, 2017 · 1 comment
Closed

Default method for an instance always overwritten by get #1121

Nilegfx opened this issue Oct 10, 2017 · 1 comment

Comments

@Nilegfx
Copy link

Nilegfx commented Oct 10, 2017

In ./lib/core/Axios.js

config = utils.merge(defaults, this.defaults, { method: 'get' }, config);

The method is always overwritten with the { method: 'get' }, so you are forced to pass the method in each request, like the following:

const myAlwaysPostAPI = axios.create({
  baseURL: 'http://localhost'
  url    : '/myResource',
});

myAlwaysPostAPI({
  method: 'post', //always forced to pass this in each API call
  data      : {key: 'value'}
});

this also affects

myAPI.defaults.method = 'post'; //does NOT work

Expected Behavier

const myAlwaysPostAPI = axios.create({
  baseURL: 'http://localhost'
  url    : '/myResource',
  method: 'post'
});

myAlwaysPostAPI({
  data: {key: 'value'}
});

I think the solution is to move the default method to defaults file, will follow this issue with a PR for that.

@emilyemorehouse
Copy link
Member

Fixed in #1122

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants