Nnodejs

nodejs/axios-to-whatwg-fetch

Replace `axios` with `fetch`

transformationmigration
Public
1 executions
Run locally
npx codemod @nodejs/axios-to-whatwg-fetch
Documentation

Axios to WHATWG Fetch Codemod

Description

This codemod transforms code using Axios to leverage the WHATWG Fetch API, which is now natively available in Node.js. By replacing Axios with Fetch, you can reduce dependencies, mitigate risks, and improve performance.

Supported Transformations

The codemod supports the following Axios methods and converts them to their Fetch equivalents:

  • axios.request(config)
  • axios.get(url[, config])
  • axios.delete(url[, config])
  • axios.head(url[, config])
  • axios.options(url[, config])
  • axios.post(url[, data[, config]])
  • axios.put(url[, data[, config]])
  • axios.patch(url[, data[, config]])
  • axios.postForm(url[, data[, config]])
  • axios.putForm(url[, data[, config]])
  • axios.patchForm(url[, data[, config]])
  • axios.request(config)

Examples

GET Request

diff

POST Request

diff
plaintext

PUT Request

diff

DELETE Request

diff

request axios Method

diff

Unsupported APIs

The codemod does not yet cover Axios features outside of direct request helpers, such as interceptors, cancel tokens, or instance configuration from axios.create().

References

Ready to contribute?

Build your own codemod and share it with the community.