Response
Class representing a HTTP response.
Extends
Body
Implements
Constructors
new Response()
new Response(body
?, init
?): Response
Create a new Response.
Parameters
Parameter | Type | Description |
---|---|---|
body ? | null | BodyInit | The body of the response. |
init ? | ResponseInit | Initialization options for the response. |
Returns
Overrides
Body.constructor
Properties
Property | Type | Description | Inherited from |
---|---|---|---|
body | null | ReadableStream <Uint8Array > | - | globalThis.Response.body Body.body |
bodyUsed | boolean | - | globalThis.Response.bodyUsed Body.bodyUsed |
headers | Headers | - | globalThis.Response.headers Body.headers |
redirected | boolean | Whether the response was redirected. | - |
status | number | HTTP status code of the response. | - |
statusText | string | Status text of the response. | - |
type | ResponseType | Type of the response. | - |
url | string | URL of the response. | - |
Accessors
ok
get
ok(): boolean
Check if the response was successful.
Returns
boolean
- True if the status is between 200 and 299, inclusive.
Implementation of
globalThis.Response.ok
Methods
arrayBuffer()
arrayBuffer(): Promise
<ArrayBuffer
>
Returns a promise that resolves with an ArrayBuffer representation of the body. If the body is null, it returns an empty ArrayBuffer.
Returns
Implementation of
globalThis.Response.arrayBuffer
Inherited from
Body.arrayBuffer
blob()
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
Implementation of
globalThis.Response.blob
Inherited from
Body.blob
clone()
clone(): Response
Clone the response.
Returns
Implementation of
globalThis.Response.clone
Throws
- This method is not implemented.
formData()
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
Implementation of
globalThis.Response.formData
Inherited from
Body.formData
json()
json(): Promise
<any
>
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
>
Implementation of
globalThis.Response.json
Inherited from
Body.json
text()
text(): Promise
<string
>
Returns a promise that resolves with a text representation of the body.
Returns
Promise
<string
>
Implementation of
globalThis.Response.text
Inherited from
Body.text
error()
static
error(): Response
Create a new error response.
Returns
- The new error response.
json()
static
json(data
, init
): Response
Create a new JSON response.
Parameters
Parameter | Type | Description |
---|---|---|
data | any | The data to include in the response body. |
init | ResponseInit | Initialization options for the response. |
Returns
- The new JSON response.
redirect()
static
redirect(url
, status
): Response
Create a new redirect response.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
url | string | URL | undefined | The URL to redirect to. |
status | number | 302 | The status code for the redirect, defaults to 302. |
Returns
- The new redirect response.