Response
The Response class represents the result of an HTTP request made using the fetch() API.
It provides access to the response body, headers, cookies, and metadata such as the status code and MIME type.
In the Scripting app, the Response API extends the standard Fetch API behavior to provide native-level enhancements, including:
- Access to structured cookie data
- Binary data handling via the
Datatype - WHATWG-compatible streaming via
body(ReadableStream<Uint8Array>) - A zero-copy
dataStream(ReadableStream<Data>) for streaming the body as nativeData - Access to expected content length, MIME type, and text encoding
Definition
Properties
Methods
json(): Promise<any>
Parses the response body as JSON.
Example
text(): Promise<string>
Reads the response body as a UTF-8 string (or using textEncodingName if available).
Example
data(): Promise<Data>
Reads the response body as a binary Data object, which can be used for file saving, image decoding, or Base64 conversion.
Example
bytes(): Promise<Uint8Array>
Reads the response as a byte array (Uint8Array).
Example
arrayBuffer(): Promise<ArrayBuffer>
Reads the response as an ArrayBuffer, useful for low-level binary operations.
Example
dataStream: ReadableStream<Data>
Streams the response body as native Data chunks. This is the zero-copy fast path: prefer it over body when you work with Data (e.g. appending chunks to a file), since body converts every chunk to Uint8Array. The body can only be consumed once, so reading dataStream makes body and the read methods (data(), json(), …) unavailable.
Example
formData(): Promise<FormData>
Parses the response body as form data (for responses with multipart/form-data content).
Example
cookies: Cookie[]
The cookies property provides direct access to the cookies set by the server via Set-Cookie headers.
Each cookie is represented by a Cookie object with structured metadata.
Cookie Type Definition
Example — Reading Cookies
Example — Manual Cookie Management
By default, Scripting’s fetch() does not automatically store or send cookies.
To reuse cookies across multiple requests, you can manually include them:
This gives you explicit cookie control similar to browser developer tools.
Relationship with Other Classes
Examples
Example 1 — Handling JSON API Responses
Example 2 — Downloading Binary Data
Example 3 — Reading Cookies from a Response
Example 4 — Manual Cookie Persistence Between Requests
Example 5 — Inspecting Metadata
Summary
The Response class in Scripting offers a rich and extensible interface for handling HTTP responses:
- Compatible with the standard Fetch API
- Adds native cookie parsing and management
- Supports binary data streams via the
Datatype - Provides full access to headers, MIME type, and encoding
- Allows seamless use with
FormDataandReadableStream
