Skip to content

Request

Make HTTP requests

Request is used to make HTTP/HTTPS network requests, supporting various response formats.

Use Request to:

Note

Use allowInsecureRequest with caution

Examples

javascript
let req = new Request("https://api.example.com/data");
let json = await req.loadJSON();
console.log(json);
javascript
let req = new Request("https://api.example.com/post");
req.method = "POST";
req.headers = { "Content-Type": "application/json" };
req.body = JSON.stringify({ name: "test" });
let response = await req.loadJSON();

Properties

url

  • Type: String

Request URL

The URL to send the request to.

javascript
req.url = "https://example.com"

method

  • Type: String

HTTP method

The HTTP method to use. Defaults to "GET".

javascript
req.method = "POST"

headers

  • Type: [String: String]

Request headers

HTTP headers to include in the request.

javascript
req.headers = { "Authorization": "Bearer token" }

body

  • Type: String

Request body

The body content for POST/PUT requests.

javascript
req.body = JSON.stringify({ key: "value" })

timeoutInterval

  • Type: Double

Timeout interval

Request timeout in seconds. Defaults to 60.

javascript
req.timeoutInterval = 30

allowInsecureRequest

  • Type: Bool

Allow insecure requests

Set to true to allow requests to servers with invalid SSL certificates. Use with caution, only for development purposes.

javascript
req.allowInsecureRequest = true

response

  • Type: JSValue

Response object

Contains response information after the request completes. Includes statusCode, headers, cookies, and mimeType.

javascript
let status = req.response.statusCode

Methods

load

Load raw data

Performs the request and returns raw Data object.

typescript
load(callback): void
  • callback - Callback with result

Returns: Promise that resolves to Data

Example:

javascript
let data = await req.load()

loadString

Load as string

Performs the request and returns response as string.

typescript
loadString(callback): void
  • callback - Callback with result

Returns: Promise that resolves to string

Example:

javascript
let text = await req.loadString()

loadJSON

Load as JSON

Performs the request and parses response as JSON.

typescript
loadJSON(callback): void
  • callback - Callback with result

Returns: Promise that resolves to parsed JSON object

Example:

javascript
let json = await req.loadJSON()

loadImage

Load as image

Performs the request and returns response as image data.

typescript
loadImage(callback): void
  • callback - Callback with result

Returns: Promise that resolves to image info with base64, width, height

Example:

javascript
let img = await req.loadImage()

addParameterToMultipart

Add parameter to multipart form

Adds a text parameter to a multipart form request.

typescript
addParameterToMultipart(name, value): void
  • name - Parameter name
  • value - Parameter value

Example:

javascript
req.addParameterToMultipart("field", "value")

addFileDataToMultipart

Add file to multipart form

Adds a file to a multipart form request.

typescript
addFileDataToMultipart(data, mimeType, name, filename): void
  • data - File data as base64 string
  • mimeType - MIME type of the file
  • name - Form field name
  • filename - File name

Example:

javascript
req.addFileDataToMultipart(base64Data, "image/png", "file", "image.png")