@shiroyasha9/axios-fetch-adapter
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Why

I had been using @vespaiach/axios-fetch-adapter for a while and it worked well. However, it's not maintained anymore and I needed it to be compatible with the latest version of Axios. So I decided to fork it and make it work with axios@1+.

Axios doesn't have an adapter for fetch API for now. So you can use this adapter for services that require fetch API (looking at you contentful 😒).

Installation and Usage

You can install the adapter directly from this repository URL or feel free to copy its source code to your project. Can use npm/yarn/bun/whatever you like.

npm install axios
npm install @shiroyasha9/axios-fetch-adapter

There are two ways to use it:

  1. Create a new instance of Axios and pass this adapter in configuration
const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  adapter: fetchAdapter
  ....
});
  1. Pass this adapter in each of request
axios.request({
  url: '/user',
  method: 'get',
  adapter: fetchAdapter
  ...
})
  1. Use with FormData
axios.request({
  url: '/user',
  method: 'post',
  adapter: fetchAdapter
  data: new FormData(formId)
  ...
})

Note

  • Since, this adapter relies on fetch API so it won't work in Node environment
  • Feel free to report any issues and I'll try to fix them!

Readme

Keywords

Package Sidebar

Install

npm i @shiroyasha9/axios-fetch-adapter

Weekly Downloads

40

Version

1.0.3

License

MIT

Unpacked Size

33.8 kB

Total Files

9

Last publish

Collaborators

  • shiroyasha9