Skip to content

Universal fetch() polyfill (FastBoot and browser) for Ember apps

License

Notifications You must be signed in to change notification settings

marcoow/ember-network

 
 

Repository files navigation

ember-network

Ember Network provides low-level networking primitives that work both in the browser and in Node.js via FastBoot.

Installation

In your Ember app or addon, run:

  • ember install ember-network

Usage

Currently, Ember Network implements the WHATWG Fetch standard. Other standards may be implemented in the future.

Fetch

import Route from "ember-route";
import fetch from "ember-network/fetch";

export default Route.extend({
  model() {
    return fetch('https://api.github.com/users/tomdale/events')
      .then(function(response) {
        return response.json();
      });
  }
});

For more information on using fetch(), see:

To see a very simple example app using FastBoot and Ember Network, see:

How It Works

At build time, Ember Network detects if the build target is FastBoot or the browser. For FastBoot, it swaps in the node-fetch library. For the browser, it swaps in GitHub's fetch polyfill. (The browser polyfill will use the native window.fetch() if available.) The appropriate version will appear in your vendor.js file.

If you'd like to write an Ember addon that does something similar, please see the annotated index.js file.

About

Universal fetch() polyfill (FastBoot and browser) for Ember apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 79.8%
  • HTML 13.5%
  • Perl 6.7%