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

Fixing default method for an instance always overwritten by get #1122

Merged

Conversation

Nilegfx
Copy link

@Nilegfx Nilegfx commented Oct 10, 2017

Fixing #1121

Description

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'}
});

@Nilegfx
Copy link
Author

Nilegfx commented Oct 23, 2017

@rubennorte @nickuraltsev @mzabriskie
guys, any updates regarding this PR?

@janko
Copy link

janko commented Nov 28, 2017

I was bitten by this as well. Not being able to set a default request method is definitely a bug, because all other options can be set.

@emilyemorehouse emilyemorehouse merged commit a105872 into axios:master Feb 20, 2018
@emilyemorehouse
Copy link
Member

This was fixed in #1342, but I prefer this implementation. Thanks!

@axios axios locked and limited conversation to collaborators May 3, 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

Successfully merging this pull request may close these issues.

None yet

4 participants