fetch basic auth code example
Example 1: how to send basic auth using fetch
fetch(url, {
...options,
headers: {
'Authorization': 'Basic ' + btoa(`${username}:${password}`)
}
})
.then(response => response.json())
.then(json => console.log(json));
Example 2: node-fetch auth basic
// for node-fetch
fetch(url, {
...
headers: {
'Authorization': 'Basic ' + Buffer.from(`${username}:${password}`, 'binary').toString('base64')
}
...
})