Please take a look here. You have there an example.
But if you want to use pure vanila here you have sth:
var request = new XMLHttpRequest()
request.open('GET', 'https://dev.azure.com/thecodemanual/_apis/projects?api-version=5.1', true)
request.setRequestHeader('Content-Type', 'application/json; charset=utf-8;');
request.setRequestHeader ("Authorization", "Basic " + btoa('Basic' + ":" + 'YOUR_PAT_TOKEN'));
request.onload = function() {
// Begin accessing JSON data here
var data = JSON.parse(this.response)
if (request.status >= 200 && request.status < 400) {
console.log(data)
} else {
console.log('error')
}
}
request.send()