$httpProvider
Configure defaults and interceptors for $http.
Use $httpProvider during module configuration to set application-wide HTTP
behavior before any request is made.
Exact provider members are documented in TypeDoc:
Defaults
Use defaults for headers, credentials, transforms, XSRF names, caching, and parameter serialization.
angular.module('app', []).config(($httpProvider) => {
$httpProvider.defaults.headers.common.Authorization = 'Bearer token';
$httpProvider.defaults.withCredentials = true;
});
Interceptors
Register interceptors to add cross-cutting request and response behavior.
angular.module('app', []).config(($httpProvider) => {
$httpProvider.interceptors.push(() => ({
request(config) {
config.headers['X-Timestamp'] = Date.now();
return config;
},
}));
});
XSRF
Add trusted origins before AngularTS sends XSRF headers to cross-origin APIs.
angular.module('app', []).config(($httpProvider) => {
$httpProvider.xsrfTrustedOrigins.push('https://api.example.com');
});
See also $http.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.