Skip to content
Merged

docs #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions docs/v1/create-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,26 @@ type ClientConfig = {
};
```

## Supported request methods
## HTTP methods

The client provides these convenience methods:
The client provides a predictable set of methods:

- client.get(path, options?)
- client.post(path, body?, options?)
- client.put(path, body?, options?)
- client.delete(path, options?)
```text
client.get(path, options?)
client.delete(path, options?)

It also provides:
client.post(path, body?, options?)
client.put(path, body?, options?)
client.patch(path, body?, options?)

- client.request(config)
client.request(config)
```

### Body vs options

- `get` and `delete` do not accept body
- `post`, `put`, and `patch` accept request body as the second argument
- `options` is used for headers, query, timeout, retry, and other settings

## GET request

Expand Down Expand Up @@ -110,13 +118,33 @@ const updated = await client.put('/users/1', {
});
```

## PATCH request

```ts
const updatedUser = await client.patch('/users/1', {
name: 'Jane',
});
```

## DELETE request

```ts
const result = await client.delete('/users/1');
```

## Low-level request API
## Request options

```ts
type RequestOptions = {
query?: Record<string, string | number | boolean | null | undefined>;
headers?: Record<string, string>;
timeout?: number;
retry?: RetryConfig;
signal?: AbortSignal;
};
```

## Low-level request

```ts
const result = await client.request({
Expand All @@ -132,28 +160,18 @@ const result = await client.request({
});
```

## Request options

For `get()` and `delete()`:

```ts
type RequestOptions = {
query?: Record<string, string | number | boolean | null | undefined>;
headers?: Record<string, string>;
timeout?: number;
};
```

For `request()`:
### Request Config

```ts
type RequestConfig = {
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
path: string;
query?: Record<string, string | number | boolean | null | undefined>;
body?: unknown;
headers?: Record<string, string>;
timeout?: number;
retry?: RetryConfig;
signal?: AbortSignal;
};
```

Expand Down
27 changes: 25 additions & 2 deletions docs/v1/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,43 @@ const client = createClient({
});
```

## GET request
## GET method

```ts
const users = await client.get('/users');
```

## POST JSON
## POST method

```ts
const createdUser = await client.post('/users', {
name: 'Tom',
});
```

## PATCH method

```ts
const updatedUser = await client.patch('/users/1', {
name: 'Jane',
});
```

## DELETE method

```ts
const deletedUser = await client.delete('/users/1');
```

## Low-level request

```ts
const singleUser = await client.request<User>({
method: 'GET',
path: '/users/2',
});
```

## Client with auth

```ts
Expand Down
9 changes: 5 additions & 4 deletions docs/v1/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ The client focuses on predictable behavior, extensibility, and a clean developer
- request timeout support
- automatic JSON parsing
- text response support
- structured error classes
- auth support
- lifecycle hooks
- retry support
- consistent error handling with structured error classes
- auth support: `bearer`, `API key` and custom
- lifecycle hooks: `beforeRequest`, `afterResponse`, `onError`
- support for `GET`, `POST`, `PUT`, `PATCH`, and `DELETE`
- retry policies
- custom `fetch` support

## Quick example
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectBadges/ProjectBadges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ProjectBadges = () => {
>
<Box
component="img"
src={`https://img.shields.io/npm/dm/${encodeURI(packageName)}`}
src={`https://img.shields.io/npm/dw/${encodeURI(packageName)}`}
alt="npm downloads"
sx={{ height: 20 }}
/>
Expand Down
Loading