Skip to content

http

The http namespace allows RayQuiro programs to communicate with REST APIs, fetch web content, and post payloads over HTTP/HTTPS.


FunctionSignatureReturn TypeDescription
http.gethttp.get(url, headers)objectPerforms an HTTP GET request.
http.posthttp.post(url, body, headers)objectPerforms an HTTP POST request.
http.requesthttp.request(options)objectGeneric configurable HTTP request.

HTTP requests return an object with the following fields:

FieldTypeDescription
statusnumberHTTP status code (e.g. 200, 404, 500).
bodystringRaw body text returned by the server.
headersobjectMap of response headers received.

var res = http.get("https://api.github.com/repos/raytolfas/rayquiro", {
"User-Agent": "RayQuiro-Client/0.2.0"
});
if (res["status"] == 200) {
var repo = json.parse(res["body"]);
print("Repository Stars: " + str(repo["stargazers_count"]));
} else {
print("Request failed with HTTP status: " + str(res["status"]));
}

var payload = json.stringify({
title: "Bug report",
body: "Found an unexpected token error",
priority: "high"
});
var res = http.post("https://example.com/api/tickets", payload, {
"Content-Type": "application/json",
"Authorization": "Bearer " + env.get("API_TOKEN")
});
print("Response status: " + str(res["status"]));
print("Response body: " + res["body"]);