The fetch() method initiates an HTTP/HTTPS network request and returns a Promise that resolves to a Response object.
It behaves similarly to the standard Fetch API available in browsers but includes native extensions optimized for Scripting’s iOS runtime environment — such as local file access, Data integration, custom redirect handling, abort control, and debugging labels.
url: stringThe URL to request. It can be:
"https://api.example.com/data""file:///var/mobile/Containers/Data/Application/..."init?: RequestInitAn optional configuration object used to customize the request’s method, headers, body, timeout, abort signal, and other options.
| Property | Type | Description | |
|---|---|---|---|
| method | string |
The HTTP method, such as "GET", "POST", "PUT", "DELETE". Defaults to "GET". |
|
| headers | HeadersInit |
The request headers. Can be a Headers object, a key-value object, or an array of [key, value] pairs. |
|
| body | Data | FormData | string | ArrayBuffer |
The request body. Only used for methods other than GET or HEAD. |
|
| allowInsecureRequest | boolean |
Whether to allow HTTP requests when running in an HTTPS context. Defaults to false. |
|
| handleRedirect | (newRequest: RedirectRequest) => Promise<RedirectRequest | null> |
Custom redirect handler. Return null to cancel the redirect. |
|
| shouldAllowRedirect | (newRequest: Request) => Promise<boolean> |
Deprecated. Use handleRedirect instead. |
|
| timeout | number |
Timeout duration in seconds. Throws an AbortError when exceeded. |
|
| signal | AbortSignal |
A signal object from AbortController that can abort the request. |
|
| cancelToken | CancelToken |
Deprecated. Use signal instead. |
|
| debugLabel | string |
A label shown in the log panel for debugging and tracing requests. |
Returns a Promise<Response>.
The Response object represents the result of the request.
Even when the HTTP status code indicates failure (e.g., 404 or 500), fetch resolves successfully with a Response.
The Promise is rejected only when:
| Error Type | Trigger Condition |
|---|---|
TypeError |
Invalid URL, unsupported protocol, or incompatible request body. |
AbortError |
The request was aborted via AbortController or timed out. |
FormDataAbortController| Class | Description |
|---|---|
Request |
Represents a network request. You can pass a Request object to fetch(request) to reuse configuration. |
Response |
Represents the result of a network operation, with helper methods such as .json(), .text(), .data(). |
AbortController / AbortSignal |
Provides a way to abort requests programmatically. |
FormData |
Builds multipart/form-data bodies for file uploads and form submissions. |
Headers |
Manages HTTP request and response headers. |
Data |
Represents binary data and supports conversion to multiple formats (e.g., Base64, hex). |
Cookie Management:
fetch does not automatically store or send cookies.
Cookies from responses can be accessed via response.cookies.
Redirects:
Redirects are automatically followed unless overridden by handleRedirect.
Concurrency: Each request runs independently and safely in parallel.
File Support:
You can upload local files using Data.fromFile() as the request body.
The fetch() API in Scripting extends the standard web Fetch interface with native capabilities:
Data binary objectsdebugLabel