O'Reilly logo

Kubernetes for Serverless Applications by Russ McKendrick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Weather

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`);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required