@zturnlibs/ztron-api


http

Interfaces

FetchOptions

Defined in: http.ts:33

Properties

body?

optional body?: HttpRequestBody

Defined in: http.ts:36

headers?

optional headers?: Record<string, string>

Defined in: http.ts:35

method?

optional method?: string

Defined in: http.ts:34

responseType?

optional responseType?: "text" | "json" | "binary"

Defined in: http.ts:40

"text"(默认)| "json" | "binary"。流式请用 fetchStream()。

timeoutMs?

optional timeoutMs?: number

Defined in: http.ts:38

N 毫秒后中止请求。


HttpResponse

Defined in: http.ts:8

Properties

binary?

optional binary?: Uint8Array<ArrayBufferLike>

Defined in: http.ts:23

responseType 为 "binary" 时提供(字节)。

body

body: string

Defined in: http.ts:12

headers

headers: Record<string, string>

Defined in: http.ts:11

json?

optional json?: unknown

Defined in: http.ts:21

responseType 为 "json" 时提供。

ok

ok: boolean

Defined in: http.ts:10

status

status: number

Defined in: http.ts:9


HttpStreamResponse

Defined in: http.ts:77

流式响应:先到 headers,body chunk 随到达逐个给出。

Properties

body

body: ReadableStream<Uint8Array<ArrayBufferLike>>

Defined in: http.ts:82

以字节流形式提供的响应体(渐进送达)。

headers

headers: Record<string, string>

Defined in: http.ts:80

ok

ok: boolean

Defined in: http.ts:79

status

status: number

Defined in: http.ts:78

Type Aliases

HttpRequestBody

HttpRequestBody = string | Uint8Array | ArrayBuffer | Record<string, unknown>

Defined in: http.ts:26

Variables

http

const http: object

Defined in: http.ts:163

Type Declaration

fetch

fetch: (url, options) => Promise<HttpResponse>

执行一个受作用域约束的 HTTP 请求;URL 超出作用域时抛出异常。

Parameters
url

string

options?

FetchOptions = {}

Returns

Promise<HttpResponse>

fetchStream

fetchStream: (url, options) => Promise<HttpStreamResponse>

执行作用域内的 HTTP 请求,响应体以流交付:status + headers 一到 promise 即 resolve,body 随每个网络 chunk(Uint8Array)到达逐个产出——应用无需缓冲整个响应;流中途出错会让 body 的读取 reject。

Parameters
url

string

options?

FetchOptions = {}

Returns

Promise<HttpStreamResponse>

Functions

fetch()

fetch(url, options?): Promise<HttpResponse>

Defined in: http.ts:67

执行一个受作用域约束的 HTTP 请求;URL 超出作用域时抛出异常。

Parameters

url

string

options?

FetchOptions = {}

Returns

Promise<HttpResponse>


fetchStream()

fetchStream(url, options?): Promise<HttpStreamResponse>

Defined in: http.ts:101

执行作用域内的 HTTP 请求,响应体以流交付:status + headers 一到 promise 即 resolve,body 随每个网络 chunk(Uint8Array)到达逐个产出——应用无需缓冲整个响应;流中途出错会让 body 的读取 reject。

Parameters

url

string

options?

FetchOptions = {}

Returns

Promise<HttpStreamResponse>