Skip to content

Instantly share code, notes, and snippets.

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 liangjun-jiang/075e0e94b4803042b4b877b5ca4fb76b to your computer and use it in GitHub Desktop.
Save liangjun-jiang/075e0e94b4803042b4b877b5ca4fb76b to your computer and use it in GitHub Desktop.
Azure Function using http.request
/*
an example that use node.js http module to make a post request.
*/
var http = require('http');
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var options = {
host: 'www.mocky.io',
port: '80',
path: '/v2/5c839741300000ca0b6b0c96',
method: 'POST'
};
var req = http.request(options, (res) => {
var body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
context.res = {
body,
'Content-Type': 'application/json'
};
context.log(context.res);
context.done();
});
}).on("error", (error) => {
context.log('error');
context.res = {
status: 500,
body: error
};
context.done();
});
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment