ApplesauceOS
Read Markdown ↗Download .md

fetch

Make an asynchronous text/JSON HTTP request.

js
fetch(url, options?)

Arguments

ArgumentTypeMeaning
urlstringAbsolute HTTP(S) URL.
optionsobjectOptional method (GET), object headers, string body, timeout in ms (default 30000; range 1..600000).

Returns

Promise of response with status, ok, url, headers, bodyUsed, text() and json(). HTTP 4xx/5xx do not reject.

Example

js
(async () => {
  const response = await fetch("https://example.com", {timeout: 5000});
  if (!response.ok) throw new Error("HTTP " + response.status);
  console.log(await response.text());
})().catch(error => { console.error(error.message); throw error; });

Notes

Text/JSON subset: no AbortSignal, streams, binary bodies or Request objects. Consume the body once. Use an async function in saved scripts; top-level await is unsupported. Also available as require("applesauceos/http").fetch.

All JavaScript APIs · Automation playbook