isomorphic-fetch Build Status

Fetch for node and Browserify. Built on top of GitHub’s WHATWG Fetch polyfill.

Warnings

  • This adds fetch as a global so that its API is consistent between client and server.
  • You must bring your own ES6 Promise compatible polyfill, I suggest es6-promise.

Installation

NPM

  1. npm install --save isomorphic-fetch es6-promise

Bower

  1. bower install --save isomorphic-fetch es6-promise

Usage

  1. require('es6-promise').polyfill();
  2. require('isomorphic-fetch');
  3. fetch('//offline-news-api.herokuapp.com/stories')
  4. .then(function(response) {
  5. if (response.status >= 400) {
  6. throw new Error("Bad response from server");
  7. }
  8. return response.json();
  9. })
  10. .then(function(stories) {
  11. console.log(stories);
  12. });

License

All open source code released by FT Labs is licenced under the MIT licence. Based on the fine work by jxck.