npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@haverstack/axios-fetch-adapter

v0.12.0

Published

An Axios adapter that uses native fetch or custom fetch functions. Useful for Cloudflare Workers and ServiceWorker environments.

Downloads

13,312

Readme

axios-fetch-adapter

npm badge checks badge codecov badge license badge

An Axios adapter that uses native fetch or a custom fetch function. Useful for Cloudflare Workers and ServiceWorker environments.

Note: This adapter was designed for version 0.21.1 of Axios, which is still used in prominent e-commerce SDKs.

Install

npm install @haverstack/axios-fetch-adapter

Use

The default use-case for this library is:

import axios from "axios";
import fetchAdapter from "@haverstack/axios-fetch-adapter";

const client = axios.create({
  adapter: fetchAdapter
});

Using with custom fetch functions

If your application does not use a globally-available fetch, you can specify your own custom fetch function instead:

import axios from "axios";
import { createFetchAdapter } from "@haverstack/axios-fetch-adapter";
import myCustomFetch from "my-custom-fetch";

const myCustomFetchAdapter = createFetchAdapter({ fetch: myCustomFetch });
const client = axios.create({
  adapter: myCustomFetchAdapter
});

If your application allows for using non-fully-qualified URLs, e.g. /foo, use the disableRequest option to pass URLs directly to your custom fetch function without creating a Request object:

import axios from "axios";
import { createFetchAdapter } from "@haverstack/axios-fetch-adapter";
import myCustomFetch from "my-custom-fetch";

const customAdapter = createFetchAdapter({
  fetch: myCustomFetch,
  disableRequest: true
});
const client = axios.create({
  adapter: myCustomFetchAdapter
});

Note: A side effect of the disableRequest option is that the AxiosResponse object will only have the request URL in its request property instead of a Request object. This means that accessing, for example, response.request.url will throw an error.

Using with the Square Node.js SDK

To use this library with the square package to manage your Square resources:

import { Client, Environment } from "square";
import fetchAdapter from "@haverstack/axios-fetch-adapter";

const client = new Client({
  accessToken,
  environment,
  unstable_httpClientOptions: { adapter: fetchAdapter }
});

Development

# 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.

Acknowledgements

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: The buildFullPath function from axios has been copied here and modified to be more flexible. Licensed MIT.

License

MIT