Module

x/dax/mod.ts>RequestBuilder

Cross-platform shell tools for Deno and Node.js inspired by zx.
Very Popular
Latest
class RequestBuilder
implements PromiseLike<RequestResponse>
import { RequestBuilder } from "https://dotland.deno.dev/x/dax@0.39.2/mod.ts";

Builder API for downloading files.

Methods

arrayBuffer(): Promise<ArrayBuffer>

Fetches and gets the response as an array buffer.

blob(): Promise<Blob>

Fetches and gets the response as a blob.

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

Fetches and gets the response.

formData(): Promise<FormData>

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): RequestBuilder
json<TResult = any>(): Promise<TResult>

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

keepalive(value: boolean): RequestBuilder
method(value: string): RequestBuilder
mode(value: RequestMode): RequestBuilder
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>, options?: PipeOptions): Promise<void>

Pipes the response body to the provided writable stream.

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

Pipes the response body to a file.

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

Pipes the response body to a file.

redirect(value: RequestRedirect): RequestBuilder
referrer(value: string | undefined): RequestBuilder
referrerPolicy(value: ReferrerPolicy | undefined): RequestBuilder
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.

text(): Promise<string>

Fetches and gets the response as text.

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

Timeout the request after the specified delay throwing a TimeoutError.

url(value: string | URL | undefined): RequestBuilder

Specifies the URL to send the request to.

[symbols.readable](): ReadableStream<Uint8Array>
import RequestBuilder
import { RequestBuilder } from "https://dotland.deno.dev/x/dax@0.39.2/mod.ts";