I just starting to learn how to develop Amazon Alexa Skills using the Alexa Skills Kit and AWS Lambda. I don't quite understand how to call an API and retrieve data from it. I found this template code from a Jordan Leigh video:
var endpoint = ""; // ENDPOINT GOES HERE
var body = "";
https.get(endpoint, (response) => {
response.on('data', (chunk) => body += chunk);
response.on('end', () => {
var data = JSON.parse(body);
var subscriberCount = data.items[0].statistics.subscriberCount;
context.succeed(
generateResponse(
buildSpeechletResponse(`Current subscriber count is ${subscriberCount}`, true),
{}
)
);
});
});
I understand that the endpoint variable will hold the url for the API, but I am unsure about the rest. In this code I believe he using a YouTube API for the current subscriber count. If I wanted to, for example, use the Dark Sky API to extract weather info, how would I go about this using this similar format?