-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer-api-call-example
34 lines (28 loc) · 1.02 KB
/
timer-api-call-example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var https = require('https');
module.exports = function (context, myTimer) {
//get a random number
var rand = Math.floor(Math.random() * 8);
//call SWAPI films API with random number
https.get("https://swapi.co/api/films/" + rand +"/", (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
var myObj = JSON.parse(data);
context.log(myObj.title);
context.log(myObj.opening_crawl);
});
}).on("error", (err) => {
context.log("Error: " + err.message);
});
var timeStamp = new Date().toISOString();
if(myTimer.isPastDue)
{
context.log('JavaScript is running late!');
}
context.log('JavaScript timer trigger function ran!', timeStamp);
context.done();
};