Skip to content

Instantly share code, notes, and snippets.

@tsmx
Last active August 2, 2022 13:43
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