Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple "hello world"-level web page intended for use with Azure Functions - paste this text into a JavaScript HTTP trigger, upload project.json to kudu, and set up MOVIE_API_KEY as an environment variable.
var request = require('request');
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var html = "<html><body><h1>didn't work</h1></body></html>"
var movieApiUrl = 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=10';
// go get your own API key: https://market.mashape.com/andruxnet/random-famous-quotes#get-endpoint
var movieApiKey = process.env['MOVIE_API_KEY'];
// context.log('MOVIE API KEY = ' + movieApiKey);
var request = require('request');
var options = {
method: 'GET',
url: movieApiUrl,
headers: {
'X-Mashape-Key': movieApiKey,
'Accept': 'application/json'
}
};
function callback(error, response, body) {
context.log(' statuc code => ' + response.statusCode);
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
html = '<html><body><h1>' + info[0].quote + '</h1> <h2 style="color:white;"><i>' + info[0].author + '</i></h2></body></html>';
//if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
headers: {
'Content-Type': 'text/html; charset=utf-8'
},
body: html
};
//}
context.done();
}
else {
context.log('* * * * error ' + error);
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
context.done();
}
}
request(options, callback);
};
{
"name": "randommoviequotes",
"version": "0.0.0",
"private": true,
"dependencies": {
"request": "~2.81.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.