HTTP headers of the response.
An instance of the Headers class.
true
if the response status code is in the range 200-299.
HTTP status code of the response.
Example: 200
for a successful response.
Status text of the response.
A short description of the status code.
Example: "OK" for status code 200.
URL of the response.
In case of redirects, this will be the final URL after all redirects have been followed.
Returns the response body as a ReadableStream
.
This property provides access to the response body as a stream of data, allowing you to read it in chunks.
Returns the response body as an ArrayBuffer
.
This method is asynchronous and returns a promise that resolves to an ArrayBuffer
containing the response body data.
const response = await impit.fetch('https://example.com');
const arrayBuffer = await response.arrayBuffer();
console.log(arrayBuffer); // ArrayBuffer([ 0x3c, 0x68, 0x74, 0x6d, 0x6c, ... ])
Note that you cannot call this method multiple times on the same response instance, as the response body can only be consumed once. Subsequent calls will result in an error.
Returns the response body as a Uint8Array
.
This method is asynchronous and returns a promise that resolves to a Uint8Array
containing the response body data.
const response = await impit.fetch('https://example.com');
const uint8Array = await response.bytes();
console.log(uint8Array); // Uint8Array([ 0x3c, 0x68, 0x74, 0x6d, 0x6c, ... ])
Note that you cannot call this method multiple times on the same response instance, as the response body can only be consumed once. Subsequent calls will result in an error.
Parses the response body as JSON.
This method is asynchronous and returns a promise that resolves to the parsed JSON object.
Returns the response body as a string.
This method is asynchronous and returns a promise that resolves to a string containing the response body data.
Represents an HTTP response.
The
ImpitResponse
class provides access to the response status, headers, and body. It also includes methods to read the response body in various formats such as text, JSON, ArrayBuffer, and as a stream.This class is designed to be API-compatible with the Fetch API Response class.