Unfetch

unfetch

Tiny 500b fetch "barely-polyfill"

  • Tiny: under 500 bytes of ES3 gzipped
  • Minimal: just fetch() with headers and text/json/xml responses
  • Familiar: a subset of the full API
  • Supported: supports IE8+ (BYOP)
  • Standalone: one function, no dependencies
  • Modern: written in ES2015, transpiled to 500b of old-school JS

🤔 What's Missing?

  • Uses simple Arrays instead of Iterables, since Arrays are iterables
  • No streaming, just Promisifies existing XMLHttpRequest response bodies

Get it: npm install --save unfetch

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// simple GET request: 
fetch('/foo')
  .then( r => r.text() )
  .then( txt => console.log(txt) )


// complex POST request with JSON, headers: 
fetch('/bear', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ hungry: true })
}).then( r => {
  open(r.headers.get('location'));
  return r.json();
})

P.S: I you are looking for all the functionalities of fetch API, isomorphic-fetch would be an apt choice.

GIF FTW!

unfetch

Suggest a module

Comments