Stratal API Reference
    Preparing search index...

    Class HttpResponse<BodyType>

    A drop-in replacement for the standard Response class to allow additional features, like mocking the response Set-Cookie header.

    new HttpResponse('Hello world', { status: 201 })
    HttpResponse.json({ name: 'John' })
    HttpResponse.formData(form)

    Type Parameters

    • BodyType extends DefaultBodyType

    Hierarchy

    • FetchResponse
      • HttpResponse
    Index

    Constructors

    • Type Parameters

      • BodyType extends DefaultBodyType

      Parameters

      • Optionalbody: NoInfer<BodyType> | null
      • Optionalinit: HttpResponseInit

      Returns HttpResponse<BodyType>

    Properties

    "[bodyType]": BodyType
    body: ReadableStream<any> | null
    bodyUsed: boolean
    cf?: any
    headers: Headers

    The headers read-only property of the with the response.

    MDN Reference

    ok: boolean

    The ok read-only property of the Response interface contains a Boolean stating whether the response was successful (status in the range 200-299) or not.

    MDN Reference

    redirected: boolean

    The redirected read-only property of the Response interface indicates whether or not the response is the result of a request you made which was redirected.

    MDN Reference

    status: number

    The status read-only property of the Response interface contains the HTTP status codes of the response.

    MDN Reference

    statusText: string

    The statusText read-only property of the Response interface contains the status message corresponding to the HTTP status code in Response.status.

    MDN Reference

    type: "default" | "error"

    The type read-only property of the Response interface contains the type of the response.

    MDN Reference

    url: string

    The url read-only property of the Response interface contains the URL of the response.

    MDN Reference

    webSocket: WebSocket | null
    STATUS_CODES_WITH_REDIRECT: number[]
    STATUS_CODES_WITHOUT_BODY: number[]

    Response status codes for responses that cannot have body.

    Methods

    • Returns Promise<ArrayBuffer>

    • Returns Promise<Blob>

    • Returns Promise<Uint8Array<ArrayBufferLike>>

    • The clone() method of the Response interface creates a clone of a response object, identical in every way, but stored in a different variable.

      MDN Reference

      Returns Response

    • Returns Promise<FormData>

    • Type Parameters

      • T

      Returns Promise<T>

    • Returns Promise<string>

    • Create a Response with an ArrayBuffer body.

      Type Parameters

      • BodyType extends ArrayBuffer | SharedArrayBuffer

      Parameters

      • Optionalbody: BodyType
      • Optionalinit: HttpResponseInit

      Returns HttpResponse<BodyType>

      const buffer = new ArrayBuffer(3)
      const view = new Uint8Array(buffer)
      view.set([1, 2, 3])

      HttpResponse.arrayBuffer(buffer)
    • Safely clones the given Response. Coerces response clone exceptions into 500 mocked responses. Handy in the environments that introduce arbitrary response cloning restrictions, like "101 Switching Protocols" cloning in "miniflare".

      Parameters

      • response: Response

      Returns Response

    • Returns HttpResponse<any>

    • Create a Response with a FormData body.

      Parameters

      • Optionalbody: FormData
      • Optionalinit: HttpResponseInit

      Returns HttpResponse<FormData>

      const data = new FormData()
      data.set('name', 'Alice')

      HttpResponse.formData(data)
    • Create a Response with a Content-Type: "text/html" body.

      Type Parameters

      • BodyType extends string

      Parameters

      • Optionalbody: BodyType | null
      • Optionalinit: HttpResponseInit

      Returns HttpResponse<BodyType>

      HttpResponse.html(`<p class="author">Jane Doe</p>`)
      HttpResponse.html(`<main id="abc-123">Main text</main>`, { status: 201 })
    • Parameters

      • status: number

      Returns boolean

    • Parameters

      • status: number

      Returns boolean

    • Returns a boolean indicating whether the given response status code represents a response that can have a body.

      Parameters

      • status: number

      Returns boolean

    • Create a Response with a Content-Type: "application/json" body.

      Type Parameters

      • BodyType extends JsonBodyType

      Parameters

      • Optionalbody: NoInfer<BodyType> | null
      • Optionalinit: HttpResponseInit

      Returns HttpResponse<BodyType>

      HttpResponse.json({ firstName: 'John' })
      HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
    • Parses the given raw HTTP headers into a Fetch API Headers instance.

      Parameters

      • rawHeaders: string[]

      Returns Headers

    • Parameters

      • url: string
      • Optionalstatus: number

      Returns Response

    • Parameters

      • url: string | undefined
      • response: Response

      Returns void

    • Create a Response with a Content-Type: "text/plain" body.

      Type Parameters

      • BodyType extends string

      Parameters

      • Optionalbody: NoInfer<BodyType> | null
      • Optionalinit: HttpResponseInit

      Returns HttpResponse<BodyType>

      HttpResponse.text('hello world')
      HttpResponse.text('Error', { status: 500 })
    • Create a Response with a Content-Type: "application/xml" body.

      Type Parameters

      • BodyType extends string

      Parameters

      • Optionalbody: BodyType | null
      • Optionalinit: HttpResponseInit

      Returns HttpResponse<BodyType>

      HttpResponse.xml(`<user name="John" />`)
      HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })