axios: Axios does not use data from config when making DELETE request

Describe the bug

Axios last version (0.20.0) does not use data from config when making DELETE request. In 0.19.2 it’s working fine

To Reproduce

axios.delete("...", { 
    data: { ids: [...] },
}).then(response => {
    ...
}).catch(error => {
    ...
});

Expected behavior

Axios send request data from config when making DELETE request

Environment

  • Axios Version 0.20.0
  • Browser Chrome
  • Browser Version 84.0.4147.125
  • Node.js Version 12.18.3
  • OS: Linux Mint
  • Additional Library Versions React 16.13.1

Additional context/Screenshots

None

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 71
  • Comments: 19 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I’m getting this same issue. It took a long time to figure out it was an issue with the package, this is probably a relatively urgent fix.

FYI the following is a work around until this is fixed

axios.request({
      ...config,
      method: 'delete',
      url,
      data
})

This seems worthy of cutting 0.20.1 to release sooner than later.

This broke multiple endpoints in subtle ways for us when updating Axios and took some time to identify. I hope for the sake of other companies that this issue is resolved quickly.

Hi,

Version 0.21.0 has been released πŸŽ‰ please use that and let us know if that solves your issue.

Thanks

I also meet this problem

Tested in runkit and confirmed. It is really a breaking change.

version axios axios.delete
0.18.0 has data has data
0.19.0/1/2 has data has data
0.20.0 has data no data

The reason is that mergeConfig always selects the next data. For other aliases with data(like post/put/patch), it is reasonable. But for aliases without data, the original utils.merge is better. We should fix it in the next release with some tests.

// lib/core/Axios.js
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  /*eslint func-names:0*/
  Axios.prototype[method] = function(url, config) {
    return this.request(mergeConfig(config || {}, {
      method: method,
      url: url
    }));
  };
});

utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  /*eslint func-names:0*/
  Axios.prototype[method] = function(url, data, config) {
    return this.request(mergeConfig(config || {}, {
      method: method,
      url: url,
      data: data
    }));
  };
});

@sparkxxxxxx DELETE with a body (data) is part of the HTTP spec.

https://tools.ietf.org/html/rfc7231#section-4.3.5

Hi,

Version 0.21.0 has been released πŸŽ‰ please use that and let us know if that solves your issue.

Thanks

Can confirm issue is fixed for us.

Kindly invite someone to test with #3282. Hope it solves the problem.

@chinesedfan I built #3282 from source and patched it into node_modules and our 6 failing DELETE tests that mock endpoint responses with data now pass πŸ‘

@wopian I’m with you.

Same problem for me, I had to revert my package-lock.json to understand what was going on.