Skip to content

Instantly share code, notes, and snippets.

@mpfund
Created April 21, 2022 21:45
Show Gist options
  • Save mpfund/8d87c008891975174764f67a812eb98a to your computer and use it in GitHub Desktop.
Save mpfund/8d87c008891975174764f67a812eb98a to your computer and use it in GitHub Desktop.
Azure function with http call
#source https://dzhavat.github.io/2019/07/09/making-http-requests-inside-azure-functions.html
const fetch = require("node-fetch"); // 1
module.exports = async function (context, req) { // 2
const accessToken = '...';
const url = 'https://api.github.com/user';
const headers = {
'Authorization': `token ${accessToken}`
};
await fetch(url, { headers }) // 3
.then(response => response.json())
.then(response => context.res.json(response)); // 4
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment