From 9bc7329f7ada4fbcdfe3c799a1ad919294a4209d Mon Sep 17 00:00:00 2001 From: Shigma Date: Thu, 22 Feb 2024 21:28:58 +0800 Subject: [PATCH] docs: config and response --- packages/core/readme.md | 90 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/packages/core/readme.md b/packages/core/readme.md index 6265e9f..1796828 100644 --- a/packages/core/readme.md +++ b/packages/core/readme.md @@ -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 + redirect?: RequestRedirect + keepAlive?: boolean + params?: Record + 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 + 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 { + 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.