-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: more documentation for builders (#8746)
* docs: readme for request-utils * docs: overiew for rest builders * make REST findRecord builder docs nice
- Loading branch information
Showing
5 changed files
with
170 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,66 @@ | ||
@ember-data/tracking | ||
============================================================================ | ||
|
||
Tracking Primitives for controlling change notification of Tracked properties when working with EmberData | ||
|
||
> Note: This is a V2 Addon, but we have intentionally configured it to act and report as a V1 Addon due | ||
to bugs with ember-auto-import. | ||
> | ||
> We can remove the V1 tag if ember-auto-import will no longer attempt | ||
to load V2 addons or if it is fixed to work with V1 addons with custom addon trees and also dedupes modules for test apps. | ||
> | ||
> You can still consume this as a normal library. | ||
> In other projects. | ||
<p align="center"> | ||
<img | ||
class="project-logo" | ||
src="./ember-data-logo-dark.svg#gh-dark-mode-only" | ||
alt="EmberData RequestUtils" | ||
width="240px" | ||
title="EmberData RequestUtils" | ||
/> | ||
<img | ||
class="project-logo" | ||
src="./ember-data-logo-light.svg#gh-light-mode-only" | ||
alt="EmberData RequestUtils" | ||
width="240px" | ||
title="EmberData RequestUtils" | ||
/> | ||
</p> | ||
|
||
<p align="center">Utilities for Requests</p> | ||
|
||
This package provides Simple utility function to assist in url building, query params, and other common request operations. | ||
|
||
It's built for [*Ember***Data**](https://github.com/emberjs/data/) but useful more broadly if you're looking for lightweight functions to assist in working with urls and query params. | ||
|
||
## Installation | ||
|
||
Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/) | ||
|
||
```no-highlight | ||
pnpm add @ember-data/request-utils | ||
``` | ||
## Utils | ||
|
||
- [buildBaseUrl]() | ||
- [sortQueryParams]() | ||
- [buildQueryParams]() | ||
- [filterEmpty]() | ||
|
||
### As a Library Primitive | ||
|
||
These primitives may be used directly or composed by request builders to provide a consistent interface for building requests. | ||
|
||
For instance: | ||
|
||
```ts | ||
import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils'; | ||
|
||
const baseURL = buildBaseURL({ | ||
host: 'https://api.example.com', | ||
namespace: 'api/v1', | ||
resourcePath: 'emberDevelopers', | ||
op: 'query', | ||
identifier: { type: 'ember-developer' } | ||
}); | ||
const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`; | ||
// => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' | ||
``` | ||
|
||
This is useful, but not as useful as the REST request builder for query which is sugar over this (and more!): | ||
|
||
```ts | ||
import { query } from '@ember-data/rest/request'; | ||
|
||
const options = query('ember-developer', { name: 'Chris', include:['pets'] }); | ||
// => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' } | ||
// Note: options will also include other request options like headers, method, etc. | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.