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

0.3.5 • Public • Published

Why

I'm going to adopt PWA to my web applications and those web apps are heavily using Axios with the default XMLHTTPRequest adapter. Hence, I have to switch to Fetch adapter; However, Axios doesn't have an adapter for fetch API for now. So I write one to use while waiting for an offical one from Axios.

Installation and Usage

You can install the adapter directly from this repository URL or feel free to copy its source code to your project.

npm install axios
npm install @vespaiach/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

  • Based on vespaiach's work

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.3.50latest

Version History

VersionDownloads (Last 7 Days)Published
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10

Package Sidebar

Install

npm i @jberma23/axios-fetch-adapter

Weekly Downloads

0

Version

0.3.5

License

MIT

Unpacked Size

11.3 kB

Total Files

7

Last publish

Collaborators

  • jberma23