Created
April 21, 2022 21:45
-
-
Save mpfund/8d87c008891975174764f67a812eb98a to your computer and use it in GitHub Desktop.
Azure function with http call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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