Skip to content

Documentation / @ember-data/active-record

This package provides utilities for working with ActiveRecord APIs.

Installation

Install using your javascript package manager of choice. For instance with pnpm

sh
pnpm add -E @ember-data/active-record
sh
npm add -E @ember-data/active-record
sh
yarn add -E @ember-data/active-record
sh
bun add --exact @ember-data/active-record

Usage

Request builders are functions that produce Fetch Options. They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.

For instance, to construct a request that would fetch a resource from your API:

ts
import { findRecord } from '@ember-data/active-record/request';

const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });

This would produce the following request object:

js
{
  url: 'https://api.example.com/v1/ember_developers/1?include=friends,pets',
  method: 'GET',
  headers: <Headers>, // 'Accept': 'application/json;charset=utf-8'
  op: 'findRecord';
  records: [{ type: 'ember-developer', id: '1' }]
}

Request builder output may be used with either requestManager.request or store.request.

ts
const data = await store.request(options);

URLs are stable. The same query will produce the same URL every time, even if the order of keys in the query or values in an array changes.

URLs follow the most common ActiveRecord format (underscored pluralized resource types).

Functions

Released under the MIT License.