forked from apalmer37/Project2_PPE_Charity_OnlineStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Covid-Latest-Totals.js
44 lines (35 loc) · 895 Bytes
/
Covid-Latest-Totals.js
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
35
36
37
38
39
40
41
42
43
44
const https = require("https");
// Endpoint for getting latest totals
const endpointUrl = "https://covid-19-data.p.rapidapi.com/totals";
// RapidAPI host
const rapidApiHost = "covid-19-data.p.rapidapi.com";
// YOUR RapidAPI key
const rapidApiKey = "a4a9dafd64mshc3dbedd703f38bbp16884djsn011747e629e7";
const options = {
headers: {
"x-rapidapi-host": rapidApiHost,
"x-rapidapi-key": rapidApiKey,
useQueryString: true,
},
};
module.exports= function (callback){
https
.get(endpointUrl, options, (res) => {
let body = [];
res.on("data", (chunk) => {
body.push(chunk);
});
res.on("end", () => {
try {
let json = JSON.parse(body);
console.log(json);
callback(json);
} catch (error) {
console.error(error.message);
}
});
})
.on("error", (error) => {
console.error(error.message);
});
};