Packages can make HTTP GET and POST requests using Utility.http. Requests run in the background so the game won't freeze while waiting for a response. The callback fires on the client thread once complete.
Utility.http.get("https://prices.runescape.wiki/api/v1/osrs/latest?id=4151", function(response, error) {
if (error) {
Utility.print("Request failed: " + error);
return;
}
var data = JSON.parse(response);
Utility.print("Abyssal whip price: " + data.data["4151"].high);
});
Utility.http.post("https://example.com/stats", JSON.stringify({ kills: 150 }), function(response, error) {
if (error) {
Utility.print("Failed: " + error);
return;
}
Utility.print("Done: " + response);
});
A custom content type can be passed as an optional fourth argument. It defaults to application/json if not provided.