Skip to content

Commit

Permalink
docs: config and response
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 22, 2024
1 parent 72cc88d commit 4d42ae9
Showing 1 changed file with 105 additions and 7 deletions.
112 changes: 105 additions & 7 deletions packages/core/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ const { status, data } = await http('https://example.com', { method: 'GET' })

## API

### Static Methods

### new Undios(config?)

### Instance Methods

#### http(url, config?)
Expand Down Expand Up @@ -85,23 +81,125 @@ interface HTTP {

Open a WebSocket connection.

> ![NOTE]
> Currently we will use [`ws`](https://github.com/websockets/ws) package to polyfill `WebSocket` in Node.js. Once Node.js has a stable WebSocket API, we will switch to it.
> [!NOTE]
>
> Currently we will use [`ws`](https://github.com/websockets/ws) package to polyfill `WebSocket` in Node.js.
>
> Once Node.js has a stable WebSocket API, we will switch to it.
### Config

```ts
interface Config {
baseURL?: string
method?: Method
headers?: Record<string, string>
redirect?: RequestRedirect
keepAlive?: boolean
params?: Record<string, any>
data?: any
responseType?: keyof ResponseTypes
timeout?: number
}
```

#### config.baseURL

The base URL of the request. If it is set, the `url` will be resolved against it.

See [URL#base](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#base).

#### config.method

See [fetch#method](https://developer.mozilla.org/en-US/docs/Web/API/fetch#method).

#### config.headers

See [fetch#headers](https://developer.mozilla.org/en-US/docs/Web/API/fetch#headers).

#### config.redirect

See [fetch#redirect](https://developer.mozilla.org/en-US/docs/Web/API/fetch#redirect).

#### config.keepAlive

See [fetch#keepalive](https://developer.mozilla.org/en-US/docs/Web/API/fetch#keepalive).

#### config.params

Additional query parameters. They will be appended to the URL.

#### config.data

The request body. Currently support below types:

- string
- URLSearchParams
- ArrayBuffer / ArrayBufferView
- Blob
- FormData
- Object (will be serialized to JSON)

#### config.responseType

Supported response types:

```ts
interface ResponseTypes {
json: any
text: string
stream: ReadableStream<Uint8Array>
blob: Blob
formdata: FormData
arraybuffer: ArrayBuffer
}
```

#### config.timeout

The request timeout in milliseconds.

#### config.proxyAgent

> ![NOTE] In order to use a proxy agent, you need to install `undios-proxy-agent`.
> [!NOTE] In order to use a proxy agent, you need to install `undios-proxy-agent`.
### Response

```ts
interface Response<T> {
status: number
statusText: string
headers: Headers
data: T
}
```

#### response.status

See [Response#status](https://developer.mozilla.org/en-US/docs/Web/API/Response/status).

#### response.statusText

See [Response#statusText](https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText).

#### response.headers

See [Response#headers](https://developer.mozilla.org/en-US/docs/Web/API/Response/headers).

#### response.data

The decoded response body.

### Static Methods

```ts
class Undios {
constructor(config?: Config)
}
```

#### Undios.Error.is(error)

```ts
function is(error: any): error is Undios.Error
```

0 comments on commit 4d42ae9

Please sign in to comment.