Skip to content

Instantly share code, notes, and snippets.

@tsmx
Last active August 2, 2022 13:43
Show Gist options
  • Save tsmx/b3105b5b24a4c65641a0222dea06a85d to your computer and use it in GitHub Desktop.
Save tsmx/b3105b5b24a4c65641a0222dea06a85d to your computer and use it in GitHub Desktop.
Set authorization header with bearer-token in got.
const got = require('got');
// get 'url' and 'token'...
got.get(url), {
responseType: 'json',
hooks: {
beforeRequest: [
options => {
options.headers['Authorization'] = 'Bearer ' + token;
}
]
}
}).then(response => {
}).catch(error => {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment