Asset - Scripts Request Master: A new era for HTTP requests in GMS 2.3+

FrostyCat

Member
Request Master
Bringing out the true potential of http_request() since 2020

Overview

This library for GMS 2.3+ provides a set of extensions for easily encoding, decoding, and sending HTTP requests. The encoding tools support application/x-www-form-urlencoded, multipart/form-data and application/json request formats, using familiar structs and arrays instead of manual string manipulations. The HTTP helper functions also enable sending requests and receiving responses at source, without a separate HTTP asynchronous event.

Downloads / Links
YoYo Marketplace: Link
GitHub: Link 1 (Request Master + JSON Struct) | Link 2 (Request Master only) | Repository | Wiki

Comparison

Post-2020 GML with Request Master:

GML:
xhr_get("https://api.steampowered.com/ISteamNews/GetNewsForApp/v2/", {
    params: { appid: 282800, count: 1 },
    done: function(res) {
        show_message("Latest news from 100% Orange Juice: " + res.data.appnews.newsitems[0].title);
    },
    fail: function() {
        show_message("Can't fetch headlines from Steam.");
    }
});
Pre-2020 stock GML
GML:
xhr_oj = http_get("https://api.steampowered.com/ISteamNews/GetNewsForApp/v2/?appid=282800&count=1");
GML:
if (async_load[? "id"] == xhr_oj) {
    switch (async_load[? "status"]) {
        case 1: break;
        case 0:
            var data = json_decode(async_load[? "result"]);
            var newsTitle = data[? "appnews"];
            newsTitle = newsTitle[? "newsitems"];
            newsTitle = newsTitle[| 0];
            newsTitle = newsTitle[? "title"];
            show_message("Latest news from 100% Orange Juice: " + newsTitle);
            ds_map_destroy(data);
        break;
        default:
            show_message("Can't fetch headlines from Steam.");
    }
}

Feedback Welcome!
If you have any suggestions for new constructors/use cases or bug reports, please open an issue or contribute on GitHub.
 
Last edited:

mikix

Member
I like it but I can't draw it, I have to use show_message. Or am I wrong?

Edit: Also, for anyone who want the content and not the title. Write this:

GML:
           // newsTitle = newsTitle[? "title"];
            newsTitle = newsTitle[? "contents"];
 
Last edited:

FrostyCat

Member
I like it but I can't draw it, I have to use show_message. Or am I wrong?
You can't put draw_text() in the callback, this is still an asynchronous procedure. You have to deposit it into an instance variable and then draw that.

Create:
GML:
theTitle = "Loading...";
xhr_get("https://api.steampowered.com/ISteamNews/GetNewsForApp/v2/", {
    params: { appid: 282800, count: 1 },
    done: function(res) {
        theTitle = "Latest news from 100% Orange Juice: " + res.data.appnews.newsitems[0].title;
    },
    fail: function() {
        theTitle = "Can't fetch headlines from Steam.";
    }
});
Draw:
GML:
draw_text(x, y, theTitle);
 
Top