Skip to content

Commit

Permalink
docs: Add config sharing section to restendpoint docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jan 17, 2024
1 parent 802719b commit ad17239
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
15 changes: 12 additions & 3 deletions docs/rest/api/Endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ render(<TodoDetail />);

</HooksPlayground>

### Configuration sharing

Use [Endpoint.extend()](#extend) instead of `{...getTodo}` (spread)

```ts
const getTodoNormalized = getTodo.extend({ schema: Todo });
const getTodoUpdatingEveryFiveSeconds = getTodo.extend({ pollFrequency: 5000 });
```

## Lifecycle

### Success
Expand Down Expand Up @@ -231,7 +240,7 @@ class User extends Entity {
pk() { return this.id;}
}

const UserDetail = new Endpoint(
const getUser = new Endpoint(
({ id }) ⇒ fetch(`/users/${id}`),
{ schema: User }
);
Expand All @@ -242,10 +251,10 @@ const UserDetail = new Endpoint(
Can be used to further customize the endpoint definition

```typescript
const UserDetail = new Endpoint(({ id }) ⇒ fetch(`/users/${id}`));
const getUser = new Endpoint(({ id }) ⇒ fetch(`/users/${id}`));


const UserDetailNormalized = UserDetail.extend({ schema: User });
const getUserNormalized = getUser.extend({ schema: User });
```

In addition to the members, `fetch` can be sent to override the fetch function.
Expand Down
21 changes: 13 additions & 8 deletions docs/rest/api/RestEndpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ const getTodo = new RestEndpoint({
});
```

### Configuration sharing

Use [RestEndpoint.extend()](#extend) instead of `{...getTodo}` (spread)

```ts
const updateTodo = getTodo.extend({ method: 'PUT' });
```

### Managing state

<TypeScriptEditor>
Expand All @@ -127,17 +135,12 @@ export class Todo extends Entity {
}
}

const getTodo = new RestEndpoint({
urlPrefix: 'https://jsonplaceholder.typicode.com',
path: '/todos/:id',
schema: Todo,
});
const updateTodo = new RestEndpoint({
export const getTodo = new RestEndpoint({
urlPrefix: 'https://jsonplaceholder.typicode.com',
path: '/todos/:id',
method: 'PUT',
schema: Todo,
});
export const updateTodo = getTodo.extend({ method: 'PUT' });
```

</TypeScriptEditor>
Expand Down Expand Up @@ -419,7 +422,9 @@ class QSEndpoint<O extends RestGenerics = any> extends RestEndpoint<O> {
import { RestEndpoint, RestGenerics } from '@data-client/rest';
import qs from 'qs';

export default class QSEndpoint<O extends RestGenerics = any> extends RestEndpoint<O> {
export default class QSEndpoint<
O extends RestGenerics = any,
> extends RestEndpoint<O> {
searchToString(searchParams) {
return qs.stringify(searchParams);
}
Expand Down

0 comments on commit ad17239

Please sign in to comment.