I have an angular application that is hitting a node API. Our backend developer has implemented basic auth on the API, and I need to send an auth header in my request.
In the angularjs documentation you can see some ways to set headers but I think this is what you are searching:
$http({
method: 'POST',
url: '/theUrl',
headers: {
'Authorization': 'Bearer ' + 'token'
//or
//'Authorization': 'Basic ' + 'token'
},
data: someData
}).then(function successCallback(response) {
$log.log("OK")
}, function errorCallback(response) {
if(response.status = 401){ // If you have set 401
$log.log("ohohoh")
}
});
I'm using this structure in my angularjs client with an ASP.NET 5 server and it works.