Class Response

Class representing a HTTP response.

Hierarchy

  • Body
    • Response

Implements

Constructors

  • Create a new Response.

    Parameters

    • Optional body: null | BodyInit

      The body of the response.

    • init: ResponseInit = {}

      Initialization options for the response.

    Returns Response

Properties

bodyUsed: boolean
headers: Headers
redirected: boolean

Whether the response was redirected.

status: number

HTTP status code of the response.

statusText: string

Status text of the response.

Type of the response.

url: string

URL of the response.

Accessors

  • get ok(): boolean
  • Check if the response was successful.

    Returns boolean

    • True if the status is between 200 and 299, inclusive.

Methods

  • Returns a promise that resolves with an ArrayBuffer representation of the body. If the body is null, it returns an empty ArrayBuffer.

    Returns Promise<ArrayBuffer>

  • Returns a promise that resolves with a Blob representation of the body. The Blob's type will be the value of the 'content-type' header.

    Returns Promise<Blob>

  • Clone the response.

    Returns Response

    Throws

    • This method is not implemented.
  • Returns a promise that resolves with a FormData representation of the body. If the body cannot be decoded as form data, it throws a TypeError.

    Returns Promise<FormData>

  • Returns a promise that resolves with a JSON representation of the body. If the body cannot be parsed as JSON, it throws a SyntaxError.

    Returns Promise<any>

  • Returns a promise that resolves with a text representation of the body.

    Returns Promise<string>

  • Create a new error response.

    Returns Response

    • The new error response.
  • Create a new JSON response.

    Parameters

    • data: any

      The data to include in the response body.

    • init: ResponseInit = {}

      Initialization options for the response.

    Returns Response

    • The new JSON response.
  • Create a new redirect response.

    Parameters

    • url: string | URL

      The URL to redirect to.

    • status: number = 302

      The status code for the redirect, defaults to 302.

    Returns Response

    • The new redirect response.

Generated using TypeDoc