Skip to content

Response

The Response() constructor creates a new Response object.

new Response();
new Response(body);
new Response(body, options);
  • body (optional)

    A object defining the body of a response. This can be null (which is the default) or one of the following:

    • ArrayBuffer
    • TypedArray
    • DataView
    • ReadableStream
    • URLSearchParams
    • String
    • string literal
  • options (optional)

    An options object containing any other data to associate with the Response

    • status: (optional)

      A number representing the http status code. e.g. 200

    • statusText: (optional)

      The status message associated with the status code, e.g. OK.

    • headers: (optional)

      An object: containing either a Headers object or object literal with String key/value pairs.

Property / MethodTypeDescription
statusnumberHTTP status code.
statusTextstringHTTP status text.
okbooleantrue if status is in the range 200–299.
redirectedbooleantrue if the response was redirected.
urlstringURL of the response.
headersHeadersResponse headers.
bodyReadableStream<Uint8Array> | nullResponse body stream.
bodyUsedbooleanWhether the body has already been consumed.
text()() => Promise<string>Reads body as a string.
json()() => Promise<any>Reads body and parses as JSON.
arrayBuffer()() => Promise<ArrayBuffer>Reads body as an ArrayBuffer.
blob()() => Promise<Blob>Reads body as a Blob.
formData()() => Promise<FormData>Reads body as FormData.
Response.json(data, init?);
Response.redirect(url, status?);
  • Response.json(data, init?) — serialises data to JSON and returns a Response with content-type: application/json. init accepts the same options as the constructor.
  • Response.redirect(url, status?) — returns a redirect response. status defaults to 302 and must be one of the valid redirect codes (301, 302, 303, 307, 308).
return Response.json({ ok: true }, { status: 201 });
return Response.redirect('https://example.com', 301);