Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/dax/src/request.ts>RequestBuilder

Cross platform shell tools for Deno inspired by zx.
Very Popular
Go to Latest
class RequestBuilder
implements PromiseLike<RequestResult>
import { RequestBuilder } from "https://deno.land/x/dax@0.24.0/src/request.ts";

Builder API for downloading files.

Methods

Fetches and gets the response as an array buffer.

Fetches and gets the response as a blob.

body(value: BodyInit | undefined)
cache(value: RequestCache | undefined)

Fetches and gets the response.

Fetches and gets the response as form data.

header(items: Record<string, string | undefined>): RequestBuilder

Sets multiple headers at the same time via an object literal.

header(name: string, value: string | undefined): RequestBuilder

Sets a header to send with the request.

integrity(value: string | undefined)
json<TResult = any>(): Promise<TResult>

Fetches and gets the response as JSON additionally setting a JSON accept header if not set.

keepalive(value: boolean)
method(value: string)
noThrow(value?: boolean): RequestBuilder

Do not throw if a non-2xx status code is received.

By default the request builder will throw when receiving a non-2xx status code. Specify this to have it not throw.

noThrow(exclusionStatusCode: number, ...additional: number[]): RequestBuilder

Do not throw if a non-2xx status code is received except for these excluded provided status codes.

This overload may be especially useful when wanting to ignore 404 status codes and have it return undefined instead. For example:

const data = await $.request(`https://crates.io/api/v1/crates/${crateName}`)
  .noThrow(404)
  .json<CratesIoMetadata | undefined>();

Note, use multiple arguments to ignore multiple status codes (ex. .noThrow(400, 404)) as multiple calls to .noThrow() will overwrite the previous.

pipeThrough<T>(transform: { writable: WritableStream<Uint8Array>; readable: ReadableStream<T>; }): Promise<ReadableStream<T>>

Pipes the response body through the provided transform.

pipeTo(dest: WritableStream<Uint8Array>)

Pipes the response body to the provided writable stream.

pipeToPath(options?: Deno.WriteFileOptions): Promise<string>

Pipes the response body to a file.

pipeToPath(path?: string | URL | undefined, options?: Deno.WriteFileOptions): Promise<string>

Pipes the response body to a file.

referrer(value: string | undefined)
referrerPolicy(value: ReferrerPolicy | undefined)
showProgress(opts: { noClear?: boolean; }): RequestBuilder

Shows a progress bar while downloading with the provided options.

showProgress(show?: boolean): RequestBuilder

Shows a progress bar while downloading.

Fetches and gets the response as text.

then<TResult1 = RequestResult, TResult2 = never>(onfulfilled?: ((value: RequestResult) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>
timeout(delay: Delay | undefined)

Timeout the request after the specified delay.

url(value: string | URL | undefined)

Specifies the URL to send the request to.

[withProgressBarFactorySymbol](factory: (message: string) => ProgressBar)