# ember-fetch-service

> The default blueprint for ember-cli addons.

Latest version **1.0.0** (published 2019-07-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-fetch-service
pnpm add ember-fetch-service
yarn add ember-fetch-service
bun add ember-fetch-service
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-07-03 |
| First published | 2019-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 8.* \|\| >= 10.* |
| Dependencies | 1 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | luxferresum |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-fetch-service
- npm.io page: https://npm.io/package/ember-fetch-service

## Dependencies (1)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^7.7.3

## Recent versions

- 1.0.0 (latest) — 2019-07-03

## README

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](CONTRIBUTING.md) guide for details.


License
------------------------------------------------------------------------------

This project is licensed under the [MIT License](LICENSE.md).

---
_Source: https://npm.io/package/ember-fetch-service · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
