|
1 |
| -@ember-data/adapter |
2 |
| -============================================================================== |
| 1 | +<p align="center"> |
| 2 | + <img |
| 3 | + class="project-logo" |
| 4 | + src="./ember-data-logo-dark.svg#gh-dark-mode-only" |
| 5 | + alt="EmberData Adapter" |
| 6 | + width="240px" |
| 7 | + title="EmberData Adapter" |
| 8 | + /> |
| 9 | + <img |
| 10 | + class="project-logo" |
| 11 | + src="./ember-data-logo-light.svg#gh-light-mode-only" |
| 12 | + alt="EmberData Adapter" |
| 13 | + width="240px" |
| 14 | + title="EmberData Adapter" |
| 15 | + /> |
| 16 | +</p> |
3 | 17 |
|
4 |
| -[Short description of the addon.] |
| 18 | +<p align="center">Provides REST and JSON:API Implementations of the legacy <a href="https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Adapter">Adapter Interface</a></p> |
5 | 19 |
|
| 20 | +> **Caution** ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used. |
| 21 | +> If starting a new app or thinking of implementing a new adapter, consider writing a [Handler](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Handler) |
| 22 | +> instead to be used with the [RequestManager](https://github.com/emberjs/data/tree/main/packages/request#readme) |
6 | 23 |
|
7 |
| -Compatibility |
8 |
| ------------------------------------------------------------------------------- |
| 24 | +## Installation |
9 | 25 |
|
10 |
| -* Ember.js v3.4 or above |
11 |
| -* Ember CLI v2.13 or above |
| 26 | +This package is currently installed when installing `ember-data`. |
12 | 27 |
|
| 28 | +If installing `@ember-data/` packages individually install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/) |
13 | 29 |
|
14 |
| -Installation |
15 |
| ------------------------------------------------------------------------------- |
| 30 | +```no-highlight |
| 31 | +pnpm add @ember-data/adapter |
| 32 | +``` |
| 33 | + |
| 34 | +## 🚀 Setup |
| 35 | + |
| 36 | +If using `ember-data` no additional setup is necesssary. |
| 37 | + |
| 38 | +> **Note** When using [ember-data](https://github.com/emberjs/data/blob/main/packages/-ember-data) the below |
| 39 | +> configuration is handled for you automatically. |
| 40 | +
|
| 41 | +To use legacy adapters you will need to have installed and configured the LegacyNetworkHandler from [@ember-data/legacy-compat](https://github.com/emberjs/data/blob/main/packages/-ember-data) |
| 42 | + |
| 43 | +```no-highlight |
| 44 | +pnpm add @ember-data/legacy-compat |
| 45 | +``` |
| 46 | + |
| 47 | +```ts |
| 48 | +import Store, { CacheHandler } from '@ember-data/store'; |
| 49 | +import RequestManager from '@ember-data/request'; |
| 50 | +import { LegacyNetworkHandler } from '@ember-data/legacy-compat'; |
| 51 | + |
| 52 | +export default class extends Store { |
| 53 | + requestManager = new RequestManager(); |
16 | 54 |
|
| 55 | + constructor(args) { |
| 56 | + super(args); |
| 57 | + this.requestManager.use([LegacyNetworkHandler]); |
| 58 | + this.requestManager.useCache(CacheHandler); |
| 59 | + } |
| 60 | +} |
17 | 61 | ```
|
18 |
| -ember install @ember-data/adapter |
| 62 | + |
| 63 | + |
| 64 | +## Usage |
| 65 | + |
| 66 | +To use as either a per-type or application adapter, export one of the |
| 67 | +implementations within the `adapters/` directory of your app as appropriate. |
| 68 | + |
| 69 | +For instance, to configure an application adapter to use `JSON:API` |
| 70 | + |
| 71 | + |
| 72 | +*app/adapters/application.ts* |
| 73 | +```ts |
| 74 | +export { default } from '@ember-data/adapter/json-api'; |
19 | 75 | ```
|
20 | 76 |
|
| 77 | +By default adapters are resolved by looking for an adapter with the same name in the adapters folder as the `type` given to `store.adapterFor(<type>)`, falling back to looking for an adapter named `application`. |
| 78 | + |
| 79 | +**Overriding Resolution** |
21 | 80 |
|
22 |
| -Usage |
23 |
| ------------------------------------------------------------------------------- |
| 81 | +If you would like to avoid using resolver semantics and your application has only one or a few adapters, you may ovveride the `adapterFor` hook on the store. |
24 | 82 |
|
25 |
| -[Longer description of how to use the addon in apps.] |
| 83 | +```ts |
| 84 | +import Store from '@ember-data/store'; |
| 85 | +import Adapter from '@ember-data/adapter/json-api'; |
26 | 86 |
|
| 87 | +class extends Store { |
| 88 | + #adapter = new Adapter(); |
| 89 | + |
| 90 | + adapterFor() { |
| 91 | + return this.#adapter; |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
27 | 95 |
|
28 |
| -License |
29 |
| ------------------------------------------------------------------------------- |
30 | 96 |
|
31 |
| -This project is licensed under the [MIT License](LICENSE.md). |
| 97 | +For the full list of APIs available read the code documentation for [@ember-data/adapter](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fadapter). You may also be interested in learning more about *Ember***Data**'s [Adapter Interface](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Adapter). |
0 commit comments