Skip to main content
Module

x/dax/mod.ts>RequestResponse

Cross-platform shell tools for Deno and Node.js inspired by zx.
Extremely Popular
Go to Latest
class RequestResponse
import { RequestResponse } from "https://deno.land/x/dax@0.39.1/mod.ts";

Response of making a request where the body can be read.

Constructors

new
RequestResponse(opts: { response: Response; originalUrl: string; progressBar: ProgressBar | undefined; abortController: RequestAbortController; })

Properties

readonly
headers: Headers

Response headers.

readonly
ok: boolean

If the response had a 2xx code.

readonly
readable: ReadableStream<Uint8Array>
readonly
redirected: boolean

If the response is the result of a redirect.

readonly
response: Response

Raw response.

readonly
signal: AbortSignal

The underlying AbortSignal used to abort the request body when a timeout is reached or when the .abort() method is called.

readonly
status: number

Status code of the response.

readonly
statusText: string

Status text of the response.

readonly
url: string

URL of the response.

Methods

abort(reason?: unknown)

Aborts

arrayBuffer(): Promise<ArrayBuffer>

Respose body as an array buffer.

Note: Returns undefined when .noThrow(404) and status code is 404.

blob(): Promise<Blob>

Response body as a blog.

Note: Returns undefined when .noThrow(404) and status code is 404.

formData(): Promise<FormData>

Response body as a form data.

Note: Returns undefined when .noThrow(404) and status code is 404.

json<TResult = any>(): Promise<TResult>

Respose body as JSON.

Note: Returns undefined when .noThrow(404) and status code is 404.

pipeThrough<T>(transform: { writable: WritableStream<Uint8Array>; readable: ReadableStream<T>; }): 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.

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.

text(): Promise<string>

Respose body as text.

Note: Returns undefined when .noThrow(404) and status code is 404.

throwIfNotOk(): void

Throws if the response doesn't have a 2xx code.

This might be useful if the request was built with .noThrow(), but otherwise this is called automatically for any non-2xx response codes.