---
title: Request
description: Performs HTTP requests.
---

Performs HTTP requests.

Performs a URL request and returns the response in an appropriate format.

## Properties

### allowInsecureRequest

Allow the request even if it is deemed insecure.

```typescript
allowInsecureRequest: bool
```

By default Scriptable will attempt to reject requests that are deemed insecure.

As an example, Scriptable will reject communicating with a server that has an invalid certificate. Such servers might be malicious and may put confidentional information at risk. By enabling this setting, those requests will be allowed.

Enable this setting at your own risk.

### body

Body to send with the request.

```typescript
body: any
```

The body will be send along the request. While this property can be any value, currently only strings and Data is supported.

Be aware that this property is ignored if you convert the request to a multipart request using `addParameterToMultipart`,
`addFileToMultipart` or `addFileDataToMultipart`.

### headers

HTTP headers to send with the request.

```typescript
headers: {string: string}
```

Key value pairs where the key is the name of an HTTP header and the value will be sent as the value for the HTTP header.

### method

HTTP method used for the request.

```typescript
method: string
```

Specifies the HTTP method to use when sending the request. The default is to send the request using the GET HTTP method.

### onRedirect

Function called upon redirect.

```typescript
onRedirect: fn(Request) -> Request
```

The function determines how redirects should be handled. By default redirects are allowed. When invoked the function is supplied with the request that we're about to redirect to. The function can return the request to continue redirecting or it can return another request to redirect to. Returning null will stop the redirect. Note that onRedirect will only be invoked on the initial request. Consecutive redirects should be handled on the initial request.

### response

Response of the request.

```typescript
response: {string: any}
```

The response is not populated until the request has been completed. The response is an object that looks like the following example.



```javascript
{
  "url": "https://example.com/",
  "statusCode": 200
  "mimeType": "application/json",
  "textEncodingName": "utf-8",
  "headers": {
    "Content-Type": "application/json;charset=utf-8",
    "Content-Length": "17671"
  },
  "cookies": [{
    "path": "/",
    "httpOnly": true,
    "domain": "www.example.com",
    "sessionOnly": true,
    "name": "JSESSIONID",
    "value": "7616271F4878CFD05182D20C45F4CEB3"
  }]
}
```



Read-only.

### timeoutInterval

Timeout interval of the request.

```typescript
timeoutInterval: number
```

If a request remains idle for longer than the timeout interval, the request is considered timed out.

The timeout interval is measured in seconds and defaults to 60 seconds.

### url

URL to send request to.

```typescript
url: string
```

## Methods

<span id="-new-request" class="api-anchor"></span>

### new Request(url)

Constructs a request.

```typescript
new Request(url: string)
```

Constructs a new request that will be sent to the provided URL. The request is not sent until an appropriate load method is called, e.g. loadImage for downloading and interpreting the response as an image.

#### Parameters

**`url` `string`**

URL to send request to.

<span id="-addfiledatatomultipart" class="api-anchor"></span>

### addFileDataToMultipart(data, mimeType, name, filename)

Adds a file to a multipart request.

```typescript
addFileDataToMultipart(data: Data, mimeType: string, name: string, filename: string)
```

Converts the request to a multipart request and adds the file to the request. Be aware that the `body` property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.

Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to "multipart/form-data".

#### Parameters

**`data` `Data`**

File data to add.

**`mimeType` `string`**

MIME type of the file to add.

**`name` `string`**

Name of the parameter which holds the file.

**`filename` `string`**

Name of the file.

<span id="-addfiletomultipart" class="api-anchor"></span>

### addFileToMultipart(filePath, name, filename)

Adds a file to a multipart request.

```typescript
addFileToMultipart(filePath: string, name: string, filename: string)
```

Converts the request to a multipart request and adds the file to the request. The function will automatically determine the MIME type of the file as well as the filename. Be aware that the `body` property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.

Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to "multipart/form-data".

#### Parameters

**`filePath` `string`**

Path of the file to add.

**`name` `string`**

Name of the parameter which holds the file.

**`filename` `string`**

Optional name of the uploaded file.

<span id="-addimagetomultipart" class="api-anchor"></span>

### addImageToMultipart(image, name, filename)

Adds an image to a multipart request.

```typescript
addImageToMultipart(image: Image, name: string, filename: string)
```

Converts the request to a multipart request and adds the image to the request. The function will automatically determine the MIME type of the file Be aware that the `body` property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.

Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to "multipart/form-data".

#### Parameters

**`image` `Image`**

Image to add.

**`name` `string`**

Name of the parameter which holds the file.

**`filename` `string`**

Optional name of the uploaded file.

<span id="-addparametertomultipart" class="api-anchor"></span>

### addParameterToMultipart(name, value)

Adds a parameter to a multipart request.

```typescript
addParameterToMultipart(name: string, value: string)
```

Converts the request to a multipart request and adds a parameter with the specified name and value. Be aware that the `body` property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.

Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to "multipart/form-data".

#### Parameters

**`name` `string`**

Name of the parameter.

**`value` `string`**

Value of the parameter.

<span id="-load" class="api-anchor"></span>

### load()

Sends request.

```typescript
load(): Promise<Data>
```

Call to send the configured request to the specified URL. The raw response is provided when the returned promise is fulfilled.

#### Return value

**`Promise<Data>`**

Promise that provides the response as data when fulfilled.

<span id="-loadimage" class="api-anchor"></span>

### loadImage()

Sends request and parses response as an image.

```typescript
loadImage(): Promise<Image>
```

Call to send the configured request to the specified URL. The response is expected to be an image.

#### Return value

**`Promise<Image>`**

Promise that provides the response as an image.

<span id="-loadjson" class="api-anchor"></span>

### loadJSON()

Sends request and parses response as JSON.

```typescript
loadJSON(): Promise<any>
```

Call to send the configured request to the specified URL. The response is expected to be a valid JSON string and is parsed into an object.

#### Return value

**`Promise<any>`**

Promise that provides the response as an object when fulfilled.

<span id="-loadstring" class="api-anchor"></span>

### loadString()

Sends request and parses response as a string.

```typescript
loadString(): Promise<string>
```

Call to send the configured request to the specified URL. The response is parsed to a string and provided when the returned promise is fulfilled.

#### Return value

**`Promise<string>`**

Promise that provides the response as a string when fulfilled.