Registry / devops / ember-ajax-fetch

ember-ajax-fetch

JSON →
library2.2.2jsnpmunverified

Ember addon that provides a fetch service with an API compatible with ember-ajax. Current version 2.2.2 requires Ember 3.28+ and Node 18+. It is a drop-in replacement using the Fetch API instead of jQuery.ajax, reducing bundle size and improving modern browser compatibility. Release cadence is low; the addon is stable and feature-complete.

devops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The fetch service must be imported from the specific path 'ember-ajax-fetch/services/fetch'. Default import from the package root does not exist.

import { inject as service } from '@ember/service'; import fetch from 'ember-ajax-fetch/services/fetch';

The service is named 'fetch', but for ember-ajax compatibility you can alias it as AjaxService.

import AjaxService from 'ember-ajax-fetch/services/fetch';

In classic Ember, use `this.get('fetch')` to access the injected service, not `this.fetch`.

const response = await this.get('fetch').request('/api/data');

Shows how to inject and use the fetch service in an Ember component, including header customization.

// app/services/fetch.js (optional override) import FetchService from 'ember-ajax-fetch/services/fetch'; export default class MyFetchService extends FetchService { get headers() { return { 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]')?.content ?? '' }; } } // Usage in a component: import Component from '@glimmer/component'; import { inject as service } from '@ember/service'; export default class ExampleComponent extends Component { @service fetch; async loadData() { try { const response = await this.fetch.request('/api/posts'); console.log(response); } catch (error) { console.error('Request failed', error); } } }
Debug
Known footguns
gotchaThe fetch service imported from 'ember-ajax-fetch/services/fetch' is a default export of a function, not a class. You cannot extend it directly; instead, create a wrapper service.
deprecatedember-ajax-fetch is intended as a replacement for ember-ajax, but ember-ajax itself is deprecated. Use native fetch or ember-ajax-fetch directly.
gotchaThe `request` method returns the parsed JSON body directly, not a Response object. Errors are thrown as ember-ajax compatible error objects.
breakingIn v2, the addon no longer supports Ember < 3.28 and Node < 18. Older versions of the addon (v1.x) used different APIs.
gotchaThe service must be injected using `@service fetch` (Octane) or `service('fetch')` (classic). Using `@service('fetch')` throws an error because the service name is 'fetch'.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
3
ahrefsbot
1
Resources