HTTP Object: Difference between revisions

From Data Islands
No edit summary
No edit summary
Line 5: Line 5:


Consuming a weather api<blockquote>jint di
Consuming a weather api<blockquote>jint di
var req = HTTP();
var req = HTTP();
req.Url="https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.405&hourly=temperature_2m";
 
req.Url="<nowiki>https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.405&hourly=temperature_2m</nowiki>";
 
req.Method="GET";
req.Method="GET";
var response = req.Send();
var response = req.Send();
var json = response.JSON;
var json = response.JSON;
di.display(response.body);
di.display(response.body);
di.display(json.latitude);
di.display(json.latitude);


var table=CreateTable();
var table=CreateTable();
table.Columns.Add("latitude");
table.Columns.Add("latitude");
table.Columns.Add("longitude");
table.Columns.Add("longitude");
table.Rows.Add(json.latitude, json.longitude);
table.Rows.Add(json.latitude, json.longitude);


//append to the island
//append to the island
di.push("weather", table, "a");


</blockquote>
di.push("weather", table, "a");</blockquote>

Revision as of 08:13, 28 May 2025

The HTTP object is used to make HTTP requests to variosu web api's.


Examples:

Consuming a weather api

jint di

var req = HTTP();

req.Url="https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.405&hourly=temperature_2m";

req.Method="GET";

var response = req.Send();

var json = response.JSON;

di.display(response.body);

di.display(json.latitude);

var table=CreateTable();

table.Columns.Add("latitude");

table.Columns.Add("longitude");

table.Rows.Add(json.latitude, json.longitude);

//append to the island

di.push("weather", table, "a");