Some more examples
Before we finish off the chapter, let's look at some more example code running in Fission, starting with a weather checker.
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`); ...