Skip to content

Default method for an instance always overwritten by get  #1121

@Nilegfx

Description

@Nilegfx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions