January 2018
Intermediate to advanced
318 pages
7h 6m
English
In the /Chapter08/weather/ folder of the repository, you will find weather.js. This is a simple Node.js function that queries the Yahoo weather API to return the current weather for a given location:
'use strict';const rp = require('request-promise-native');module.exports = async function (context) { const stringBody = JSON.stringify(context.request.body); const body = JSON.parse(stringBody); const location = body.location; if (!location) { return { status: 400, body: { text: 'You must provide a location.' } }; } try { const response = await rp(`https://query.yahooapis.com/v1/public/yql?q=select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="${location}") and u="c"&format=json`);Read now
Unlock full access