GitXplorerGitXplorer
l

ember-fetch-service

public
2 stars
0 forks
22 issues

Commits

List of commits on branch master.
Unverified
f7367e7fc7a244ff874a287daa66aff017e9ba90

test for overwrite

lluxzeitlos committed 6 years ago
Unverified
609a42a1df622a12491973eefaa413cde6ed170e

first version with working headers from service

lluxzeitlos committed 6 years ago
Unverified
3d847eeaaec88dc3f39061d139fa01695960c3fa

Initial Commit from Ember CLI v3.10.1

eember-tomster committed 6 years ago

README

The README file for this repository.

ember-fetch-service

Alternative to ember-ajax that uses the fetch API provided by ember-fetch instead of jQuery. Currently this addon has significantly less features then ember-ajax.

Compatibility

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

ember install ember-fetch-service

Usage

This addon provides a fetch service that can be injected. The fetch addon has a method fetch that implements the fetch API:

import { inject as service } from '@ember/service';

export default Component.extend({
  fetch: service(),
  actions: {
    async doSomething() {
      const res = await this.fetch.fetch('/data');
      console.log(await res.text());
    }
  }
});

custom headers

To implement custom headers the fetch service can be overwritten:

// app/services/fetch.js

import Ember from 'ember';
import FetchService from 'ember-fetch-service/services/fetch';

export default FetchService.extend({
  session: Ember.inject.service(),
  headers: Ember.computed('session.authToken', {
    get() {
      let headers = {};
      const authToken = this.get('session.authToken');
      if (authToken) {
        headers['auth-token'] = authToken;
      }
      return headers;
    }
  })
});

Any headers specified with the fetch() call will overwrite headers specified on the service.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.