Docs

loadURL

Synchronously loads content from a URL and returns a response object.

Syntax

loadURL(url, options?)

Parameters

Return value

A URLResponse object containing the response data and metadata.

URLResponse Properties

URLResponse Methods

text()

Returns the response body as a string.

json()

Parses the response body as JSON and returns the resulting object.

arrayBuffer()

Returns the response body as an ArrayBuffer.

Examples

// Load a web page
let response = loadURL("https://httpbin.org/get")
let data = response.json()
data.url
"https://httpbin.org/get"
// Check status
let response = loadURL("https://example.com/api/data")
response.status
404
// Access headers
let response = loadURL("https://httpbin.org/headers")
response.headers["Content-Type"]
"application/json"

Notes

See also