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 9bc7329
Showing 1 changed file with 89 additions and 1 deletion.
90 changes: 89 additions & 1 deletion packages/core/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,110 @@ 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.
>
> 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`.
### 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/headers).

#### response.statusText

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

#### response.headers

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

#### response.data

The decoded response body.

0 comments on commit 9bc7329

Please sign in to comment.