isomorphic-unfetch
TypeScript icon, indicating that this package has built-in type declarations

4.0.2 • Public • Published

Isomorphic Unfetch

Switches between unfetch & node-fetch for client & server.

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

Note: This module uses node-fetch 3.x, which is ES Module and requires Node >= 12.20.0.

$ npm i isomorphic-unfetch

Then with a module bundler like rollup or webpack, use as you would anything else:

// using ES6 modules
import fetch from "isomorphic-unfetch";

// using CommonJS modules
const fetch = require("isomorphic-unfetch");

Usage

As a ponyfill:

import fetch from "isomorphic-unfetch";

fetch("/foo.json")
  .then((r) => r.json())
  .then((data) => {
    console.log(data);
  });

Globally, as a polyfill:

import "isomorphic-unfetch";

// "fetch" is now installed globally if it wasn't already available

fetch("/foo.json")
  .then((r) => r.json())
  .then((data) => {
    console.log(data);
  });

License

MIT License © Jason Miller

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.0.2119,758latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.2119,758
4.0.167
4.0.0549
3.1.02,202,696
3.0.029,184
2.1.15,760
2.1.012
2.0.02,136
1.0.023
0.1.03

Package Sidebar

Install

npm i isomorphic-unfetch

Weekly Downloads

2,360,188

Version

4.0.2

License

MIT

Unpacked Size

3.38 kB

Total Files

7

Last publish

Collaborators

  • developit