Skip to main content
Module

x/dax/mod.ts>RequestBuilder

Cross platform shell tools for Deno inspired by zx.
Very Popular
Go to Latest
class RequestBuilder
implements PromiseLike<RequestResult>
Re-export
import { RequestBuilder } from "https://deno.land/x/dax@0.9.0/mod.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.

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.

referrer(value: string | undefined)
referrerPolicy(value: ReferrerPolicy | undefined)

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(ms: number | undefined)

Timeout the request after the specified number of milliseconds

url(value: string | URL | undefined)

Specifies the URL to send the request to.