Skip to content

Commit

Permalink
docs: more documentation for builders (#8746)
Browse files Browse the repository at this point in the history
* docs: readme for request-utils

* docs: overiew for rest builders

* make REST findRecord builder docs nice
  • Loading branch information
runspired committed Jul 28, 2023
1 parent 96cad26 commit 2ba6182
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 19 deletions.
79 changes: 66 additions & 13 deletions packages/request-utils/README.md
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.
```
12 changes: 12 additions & 0 deletions packages/request-utils/ember-data-logo-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2ba6182

Please sign in to comment.