how to do basic authentication with fetch api

JavaScript
headers.set('Authorization', 'Basic ' + base64.encode(username + ":" + password));
Source

Also in JavaScript: