Skip to main content
zerotal

Documentation


Documentation / zerotal / http / PendingRequest

Class: PendingRequest

Defined in: packages/core/src/http/HttpClient.ts:123

Fluent HTTP request builder.

Can be awaited directly (await Http.get(url)) or chained for shorthand (await Http.post(url, data).json()).

Implements

Constructors

Constructor

new PendingRequest(_method, _url): PendingRequest

Defined in: packages/core/src/http/HttpClient.ts:131

Parameters

_method

HttpMethod

_url

string

Returns

PendingRequest

Configuration

withHeaders()

withHeaders(headers): this

Defined in: packages/core/src/http/HttpClient.ts:140

Merge additional headers into the request.

Parameters

headers

Record<string, string>

Returns

this


withToken()

withToken(token): this

Defined in: packages/core/src/http/HttpClient.ts:149

Set a Bearer token in the Authorization header.

Parameters

token

string

Returns

this


withBasicAuth()

withBasicAuth(username, password): this

Defined in: packages/core/src/http/HttpClient.ts:158

Set HTTP Basic Auth credentials.

Parameters

username

string

password

string

Returns

this


acceptJson()

acceptJson(): this

Defined in: packages/core/src/http/HttpClient.ts:168

Set an Accept: application/json header.

Returns

this


withJson()

withJson(data): this

Defined in: packages/core/src/http/HttpClient.ts:196

Attach a JSON body. Used internally — prefer passing data to Http.post().

Parameters

data

unknown

Returns

this


withFormData()

withFormData(data): this

Defined in: packages/core/src/http/HttpClient.ts:207

Attach a FormData body.

Parameters

data

FormData

Returns

this

Other

then()

then<TResult1, TResult2>(onfulfilled?, onrejected?): PromiseLike<TResult1 | TResult2>

Defined in: packages/core/src/http/HttpClient.ts:283

Attaches callbacks for the resolution and/or rejection of the Promise.

Type Parameters

TResult1

TResult1 = HttpClientResponse

TResult2

TResult2 = never

Parameters

onfulfilled?

((value) => TResult1 | PromiseLike<TResult1>) | null

The callback to execute when the Promise is resolved.

onrejected?

((reason) => TResult2 | PromiseLike<TResult2>) | null

The callback to execute when the Promise is rejected.

Returns

PromiseLike<TResult1 | TResult2>

A Promise for the completion of which ever callback is executed.

Implementation of

PromiseLike.then

Responses

send()

send(): Promise<HttpClientResponse>

Defined in: packages/core/src/http/HttpClient.ts:220

Execute the request and return an HttpClientResponse.

Returns

Promise<HttpClientResponse>

Throws

the last error encountered after all retry attempts are exhausted (e.g. a network failure or AbortSignal.timeout abort).

Throws

when Http.fake() is active but no stub matches the URL.


json()

json<T>(): Promise<T>

Defined in: packages/core/src/http/HttpClient.ts:270

Shorthand: send and deserialize JSON response body.

Type Parameters

T

T = unknown

Returns

Promise<T>


text()

text(): Promise<string>

Defined in: packages/core/src/http/HttpClient.ts:278

Shorthand: send and return the text body.

Returns

Promise<string>

Retries & resilience

timeout()

timeout(ms): this

Defined in: packages/core/src/http/HttpClient.ts:177

Abort the request after the given number of milliseconds.

Parameters

ms

number

Returns

this


retry()

retry(times, delay?): this

Defined in: packages/core/src/http/HttpClient.ts:186

Retry failed requests up to times times, with optional delay in ms.

Parameters

times

number

delay?

number = 100

Returns

this