Notch Notch Manual 0.9.23
 Light | Dark
HTTPGet

HTTPGet

Purpose #

Calls a URL and returns the payload of the HTTP response as a string.

In most cases you will want to use the NFetch function which supersedes the HTTPGet function.
This is a synchronous call and hence will block rendering until it completes (which could take hundreds of milliseconds). As such it is usually used at the start of a scene in the first frame.
Only HTTP is supported at this time. Use NFetch function for HTTPS.

Syntax #

String HTTPGet(String url);

Parameters

urlThe url to call.
returns the payload of the HTTP response as a string.

Example #

This example pulls JSON from an example HTTP endpoint. The JSON is an array of objects, with an element named title.

function OnKeyPress(key)
{
    Log('Got keypress: ' + key);
    if (key == 'P')
    {
        Log("Getting items from API");
        var data = HTTPGet("http://jsonplaceholder.typicode.com/posts");
        items = JSON.parse(data);
        for (i in items)
        {
            Log(items[i].title);
        }
    }
}