Axios Ky Adapter
An Axios adapter for Ky, a tiny and elegant HTTP client based on the browser Fetch API

This is an adapter for those who would like to use the Fetch API in Axios.
I used ky because it simplifies a lot of things, but behind the scenes all requests are done with fetch.
So if you have an old project that still uses Axios / XHR, and want to switch to the newer standard, then just throw this adapter in and you're good to go!
I've implemented most of the features available in the built-in Axios XHR Adapter, so it should work as before.
Installation
Using npm:
$ npm install axios-ky-adapter
Usage
const axios = require('axios');
const kyAdapter = require('axios-ky-adapter');
axios.get('https://example.com', {
adapter: kyAdapter
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
})
You can even pass some options directly to ky (which will be passed on to fetch), if you want:
const axios = require('axios');
const kyAdapter = require('axios-ky-adapter');
const fetch = require('isomorphic-unfetch');
kyAdapter.kyOptions = {
mode: 'cors',
fetch,
};
axios.get('https://example.com', {
adapter: kyAdapter
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
})
Browser / Node.js support
This adapter uses ky-universal
so it should work in the browser and in Node.js.
For more information check the ky and ky-universal docs!
Related
- axios - Promise based HTTP client for the browser and node.js
- ky - Tiny and elegant HTTP client based on the browser Fetch API
- ky-universal - Use Ky in both Node.js and browsers