Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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