I'm calling a back-end server that I cannot control. Currently it's using jQuery ajax like this:
return $.ajax({
type: "POST",
url: "/api/cases/store",
contentType: "application/json",
data: JSON.stringify(parameters),
headers: { "Authorization": cred } : {}
}) // ... etc.
I want to convert it to use the $resource
service, and got it working doing this
$http.defaults.headers.common['Authorization'] = cred;
return $resource('/api/cases/store').save();
The only problem is that I'm having to set the global $http
service defaults with the auth credentials.
I am seeing that you're supposed to be able to pass in custom headers with the $http
call, and now with $resource
calls, but I can't find any examples of how to do it in my case (with a POST).
I also can't find anything on this in the AngularJS documentation. How do you guys figure this stuff out? The docs are so bad!