Isomorphic Fetch API

3.0.0 · maintenance · verified Sun Apr 19

Isomorphic-fetch is a JavaScript library that provides the WHATWG Fetch API for both Node.js and browser environments. Its current stable version is 3.0.0. The package operates as a polyfill, meaning it modifies the global scope to add the `fetch` function and related constructs like `Headers`, `Request`, and `Response`. For server-side operations, it leverages `node-fetch`, while for client-side, it's built on GitHub's WHATWG Fetch polyfill. Its release cadence has slowed, with the last major version (v3.0.0) released significantly after previous iterations, suggesting a maintenance rather than active development phase. A key differentiator is its polyfill approach, which automatically makes `fetch` available globally, contrasting with 'ponyfill' alternatives like `fetch-ponyfill` or `cross-fetch` that avoid global pollution. This design choice aims for API consistency but requires users to be aware of global modifications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage by performing a GET request to an API, handling the response, and logging data or errors.

require('isomorphic-fetch');

fetch('//offline-news-api.herokuapp.com/stories')
	.then(function(response) {
		if (response.status >= 400) {
			throw new Error("Bad response from server");
		}
		return response.json();
	})
	.then(function(stories) {
		console.log(stories);
	})
	.catch(function(error) {
		console.error('Fetch failed:', error);
	});

view raw JSON →