Options
All
  • Public
  • Public/Protected
  • All
Menu

Class to work with server response data

Type parameters

  • D: Nullable<string | JSONLikeValue | ArrayBuffer | Blob | Document | unknown> = unknown

    response data type

Hierarchy

  • default

Index

Constructors

Properties

Response body value

clone: () => default<D>

Type declaration

    • Creates a clone of a response object, identical in every way, but stored in a different variable

      Returns default<D>

decoders: WrappedDecoder<unknown, unknown>[]

List of response decoders

emitter: EventEmitter2 = ...

Event emitter to broadcast response events

headers: Readonly<default>

Set of response headers

important?: boolean

A meta flag that indicates that the request is important: is usually used with decoders to indicate that the request needs to be executed as soon as possible

jsonReviver?: JSONCb

Reviver function for JSON.parse

default

convertIfDate

ok: boolean

True if the response status matches with a successful status codes (by default it should match range from 200 to 299)

okStatuses: OkStatuses

A list of status codes (or a single code) that match successful operation. Also, you can pass a range of codes.

parent?: default<unknown>

Parent operation promise

redirected: boolean

True if the response was obtained through a redirect

sourceResponseType?: ResponseType

Original type of the response data

status: number

Response status code

statusText: string

Response status text

streamDecoders: WrappedStreamDecoder<unknown, unknown>[]

List of response decoders to apply for chunks when you are parsing response in a stream form

url: string

The resolved request URL (after resolving redirects, etc.)

Accessors

  • get bodyUsed(): boolean
  • set bodyUsed(value: boolean): void
  • get streamUsed(): boolean
  • set streamUsed(value: boolean): void

Methods

  • arrayBuffer(): default<ArrayBuffer>
  • Parses the response body and returns a promise with the result. The operation result is memoized, and you can't parse the response as a stream after invoking this method.

    A way to parse data is based on the response Content-Type header or a passed responseType constructor option. Also, a sequence of decoders is applied to the parsed result if they are passed with a decoders constructor option.

    Returns default<null | D>

  • decodeStream<T>(): AsyncIterableIterator<T>
  • Parses the response body as a stream and yields chunks via an async iterator. You can't parse the response as a whole data after invoking this method.

    A way to parse data chunks is based on the response Content-Type header or a passed responseType constructor option. Also, a sequence of stream decoders is applied to the parsed chunk if they are passed with a streamDecoders constructor option.

    Type parameters

    • T = unknown

    Returns AsyncIterableIterator<T>

  • decodeToBlob(data: unknown, type?: string): Blob
  • decodeToString(data: unknown, encoding?: string): default<string>
  • getHeader(name: string): CanUndef<string>
  • jsonStream(): AsyncIterableIterator<Token>
  • stream(): AsyncIterableIterator<undefined | ArrayBuffer>
  • Parses the response data stream as an ArrayBuffer chunks and yields them via an async iterator

    Returns AsyncIterableIterator<undefined | ArrayBuffer>

  • textStream(): AsyncIterableIterator<string>