Adding The Aurelia Fetch Client Into An Aurelia CLI Project

Aurelia 1

So you’re using the CLI to build your next Aurelia application and you want to use the Fetch client? You might have noticed by default it does not come configured with the Fetch client. Fortunately, adding it in is a piece of cake.

Firstly, we want to install the Fetch Client as well as a Fetch polyfill:

npm install aurelia-fetch-client whatwg-fetch --save

Now open up aurelia_project/aurelia.json

At the bottom in the bundles section, more specifically vendor-bundle.js look for the prepend section and add in the polyfill as this will be global and we want to include it before anything else. You might notice I put it above the RequireJS line.

"prepend": [
  "node_modules/bluebird/js/browser/bluebird.core.js",
  "node_modules/whatwg-fetch/fetch.js",
  "scripts/require.js"
],

Now e need to add into the dependencies section in the vendor bundle the reference to the aurelia-fetch-client dependency. I like things being in alphabetical order, so I put it above aurelia-framework.

"aurelia-fetch-client",

Now you can use the Fetch client in your apps import {HttpClient} from 'aurelia-fetch-client';

Announcing Discover Aurelia

Update: I am working in recovering the site. I moved servers and some data was corrupted. The site will be down until it’s fixed. Since early …

Injection With Inheritance in Aurelia

In Aurelia if you have a parent/base class and one or more children that inherit from this class AND the parent class has some injectables via …