An Axios adapter that uses native fetch
. Useful for Cloudflare Workers and ServiceWorker environments.
npm install @haverstack/axios-fetch-adapter
import axios from "axios";
import fetchAdapter from "@haverstack/axios-fetch-adapter";
const client = axios.create({
adapter: fetchAdapter
});
To use with the Square API:
import { Client, Environment } from "square";
import fetchAdapter from "@haverstack/axios-fetch-adapter";
const client = new Client({
accessToken,
environment,
unstable_httpClientOptions: { adapter: fetchAdapter }
});
# Run tests
npm run test
# Check tests, linting, and formatting
npm run check
# Fix linting and formatting
npm run fix
A Miniflare testing environment is used in order to simulate a Cloudflare Worker or a ServiceWorker. This testing environment is also useful because Node does not have a native implementation of fetch
.
The code in this repo draws heavily from the following projects:
- vespaiach/axios-fetch-adapter: Most of the initial code in this repo was copied from here. Licensed MIT.
- axios/axios: Rather than import
axios
for this repo, the necessary types and utility functions were copied directly. Licensed MIT.