///

Http Class

Warning: Macros that reference Http are blocked on macro sharing. Remove Http.get(...) and Http.post(...) calls if you want the macro to be shareable.

Http.get(url)

Perform a GET request and return the response body as a string.

let result = Http.get('https://example.com'); console.log(result);

Http.post(url, jsonBody)

Perform a JSON POST request and return the response body as a string.

let result = Http.post('https://example.com', '{"name":"MacroForge"}'); console.log(result);

Http.request(url, opts?)

Perform any request and return the whole response: { ok, status, body, headers }. opts takes method, body (string or object), headers and timeout.

let result = Http.request('https://example.com', 'demo'); console.log(result);

Example:

let res = Http.request("https://example.com/status.json"); if (res.ok) { let data = JSON.parse(res.body); console.log(data.state); } else { console.log("Request failed with status " + res.status); }

Http.get() and Http.post() return only the body, so a 404 error page reads exactly like a successful answer, and a connection failure comes back as a string starting Error: , which a real response could also contain. Use Http.request() when the script needs to know whether the call worked. Failures are also logged to the script console.