Skip to content

Commit

Permalink
docs: RestEndpoint body example uses EndpointPlayground
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jun 22, 2024
1 parent 845a22e commit da255ba
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/rest/api/RestEndpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ used** in any way - this only determines [typing](#typing).

This is only used by endpoings with a method that uses body: 'POST', 'PUT', 'PATCH'.

<TypeScriptEditor>
<EndpointPlayground input="https://site.com/cool" init={{method: 'POST', body: '{ "url": "/" }', headers: {'Content-Type': 'application/json'}}}>

```ts {4}
const updateSite = new RestEndpoint({
Expand All @@ -550,7 +550,7 @@ const updateSite = new RestEndpoint({
updateSite({ slug: 'cool' }, { url: '/' });
```

</TypeScriptEditor>
</EndpointPlayground>

### paginationField

Expand Down
8 changes: 4 additions & 4 deletions docs/rest/api/createResource.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Commonly used with [useSuspense()](/docs/api/useSuspense), [Controller.invalidat
[RestEndpoint.push](./RestEndpoint.md#push) creates a new entity and pushes it to the end of getList. Use [getList.unshift](#unshift)
to place at the beginning instead.

<EndpointPlayground input="/react/posts?author=clara" init={{method: 'POST', headers: {'Content-Type': 'application/json', Body: JSON.stringify({ "title": "winning" })}}} status={201} response={{ "id": "2","group": "react","title": "winning",author: 'clara',}}>
<EndpointPlayground input="/react/posts?author=clara" init={{method: 'POST', headers: {'Content-Type': 'application/json'},body: JSON.stringify({ "title": "winning" })}} status={201} response={{ "id": "2","group": "react","title": "winning",author: 'clara',}}>

```typescript title="Post" collapsed
export default class Post extends Entity {
Expand Down Expand Up @@ -349,7 +349,7 @@ Commonly used with [Controller.fetch](/docs/api/Controller#fetch)

[RestEndpoint.unshift](./RestEndpoint.md#unshift) creates a new entity and pushes it to the beginning of getList.

<EndpointPlayground input="/react/posts?author=clara" init={{method: 'POST', headers: {'Content-Type': 'application/json', Body: JSON.stringify({ "title": "winning" })}}} status={201} response={{ "id": "2","group": "react","title": "winning",author: 'clara',}}>
<EndpointPlayground input="/react/posts?author=clara" init={{method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ "title": "winning" })}} status={201} response={{ "id": "2","group": "react","title": "winning",author: 'clara',}}>

```typescript title="Post" collapsed
export default class Post extends Entity {
Expand Down Expand Up @@ -449,7 +449,7 @@ Commonly used with [Controller.fetch](/docs/api/Controller#fetch)

Update an entity.

<EndpointPlayground input="/react/posts/1" init={{method: 'PUT', headers: {'Content-Type': 'application/json', Body: JSON.stringify({ "title": "updated title", author: 'clara' })}}} status={200} response={{ "id": "1","group": "react","title": "updated title",author: 'clara',}}>
<EndpointPlayground input="/react/posts/1" init={{method: 'PUT', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ "title": "updated title", author: 'clara' })}} status={200} response={{ "id": "1","group": "react","title": "updated title",author: 'clara',}}>

```typescript title="Post" collapsed
export default class Post extends Entity {
Expand Down Expand Up @@ -495,7 +495,7 @@ Commonly used with [Controller.fetch](/docs/api/Controller#fetch)

Update some subset of fields of an entity.

<EndpointPlayground input="/react/posts/1" init={{method: 'PATCH', headers: {'Content-Type': 'application/json', Body: JSON.stringify({ "title": "updated title" })}}} status={200} response={{ "id": "1","group": "react","title": "updated title",author: 'clara',}}>
<EndpointPlayground input="/react/posts/1" init={{method: 'PATCH', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ "title": "updated title" })}} status={200} response={{ "id": "1","group": "react","title": "updated title",author: 'clara',}}>

```typescript title="Post" collapsed
export default class Post extends Entity {
Expand Down
4 changes: 0 additions & 4 deletions packages/rest/typescript-tests/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ it('should precisely type function arguments', () => {
() => requiredSearch({ userId: 'hi' }, { userId: 'hi' });

() => undef();
// @ts-ignore TODO
() => undef({});
// @ts-ignore TODO
() => undef({ id: '5' });
// @ts-expect-error
() => undef({ userId: 'hi' });
Expand Down Expand Up @@ -412,9 +410,7 @@ it('should precisely type function arguments', () => {
() => requiredSearch({ userId: 'hi' }, { userId: 'hi' });

() => undef();
// @ts-ignore TODO
() => undef({});
// @ts-ignore TODO
() => undef({ id: '5' });
// @ts-expect-error
() => undef(5);
Expand Down
1 change: 0 additions & 1 deletion scripts/testSetupNative.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import('node-fetch').then(({ default: fetch }) => {
// @ts-ignore
// eslint-disable-next-line no-undef
globalThis.fetch = fetch;
});
3 changes: 3 additions & 0 deletions website/src/components/HTTP/Request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default function Request({ input, init }: Props) {
Object.entries(init.headers).forEach(([key, value]) => {
text += `\n${key}: ${value}`;
});
if (init.body) {
text += `\n${'Body'}: ${init.body}`;
}
return (
<div>
<Header small>Request</Header>
Expand Down

0 comments on commit da255ba

Please sign in to comment.