Isomorphic-fetch

isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify

fetch from GitHub makes it easier to make web requests and handle responses than using an XMLHttpRequest. This polyfill is written as closely as possible to the standard Fetch specification.

Well, fetch was in the nmotw queue for quite some time now, but this week seems to be special as FF nightly and Chrome canary rolled out this API ;)

Install it: npm install isomorphic-fetch

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
// Fetch random XKCD comic.

require('isomorphic-fetch');

fetch('http://xkcd-imgs.herokuapp.com/')
    .then(function(response) {
        return response.json();
    }).then(function(res) {
        console.log(res)
    }).catch(function(ex) {
        console.log('failed', ex)
    });

Would log something like:

1
2
{ url: 'http://imgs.xkcd.com/comics/wikifriends.png',
  title: 'It\'s crazy how much my gut opinion of a movie/song is swayed by what other people say, regardless of how I felt coming out of the theater.' }

GIF FTW!

isomorphic-fetch

Thanks to Matt Andrews for isomorphic-fetch (:

Suggest a module

Comments