$http
interceptors intercept requests/responses, useful for adding auth tokens or handling errors globally. For API authentication, an interceptor can attach JWT tokens to headers, enhancing maintainability by centralizing auth handling.
app.factory('authInterceptor', function() {
return {
request: function(config) {
config.headers.Authorization = 'Bearer token';
return config;
}
};
});
$httpProvider.interceptors.push('authInterceptor');