Skip to content

Instantly share code, notes, and snippets.

@macdonst
Created September 4, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macdonst/d3d1eaa7413bec4a1488e3efeb7de330 to your computer and use it in GitHub Desktop.
Save macdonst/d3d1eaa7413bec4a1488e3efeb7de330 to your computer and use it in GitHub Desktop.
MS Azure Function to ask Wolfram Alpha a question
const fetch = require('node-fetch');
const credentials = require('./credentials');
module.exports = async function(context, req) {
if (req.query.searchTerm || (req.body && req.body.searchTerm)) {
const searchTerm = req.query.searchTerm ||
req.body.searchTerm;
let url = `http://api.wolframalpha.com/v2/query?input=${searchTerm}&appid=${
credentials.wolfram
}`;
await fetch(url)
.then(res => res.text())
.then(text => {
context.res = {
status: 200,
headers: { 'Content-Type': 'text/plain' },
body: text
};
context.done();
});
} else {
context.res = {
status: 400,
body: 'Please pass a name on the query string or in the request body'
};
}
context.done();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment