Santosh Kumar Adidawarpu
How to add HTTP headers using Interceptors?
By Santosh Kumar Adidawarpu in .NET on Feb 11 2017
  • Santosh Kumar Adidawarpu
    Feb, 2017 11

    app.module('appName').factory('tokenInterceptor', ['$q', function($q) {return {request: function(config) {config.headers = config.headers || {};config.headers['X-Access-Token'] = 'xYRTT342aa@@55#$@';config.headers['X-User-Key'] = '[email protected]'config.headers['Content-Type'] = "application/json";return config || $q.when(config);},response: function(res) {return response || $q.when(res);}};}]);app.module('appName').config(['$httpProvider', function($httpProvider) { $httpProvider.interceptors.push('tokenInterceptor'); }]);Angular will call interceptors when a request is done to the server.

    • 1
  • Rajkiran Swain
    Jun, 2017 7

    Config :app.config([ '$httpProvider', function($httpProvider) {$httpProvider.interceptors.push('APIInterceptor'); } ]); Service :app.service('APIInterceptor', [function() {var service = this;service.request = function(config) {config.headers.YOUR_HEADER= YOUR_HEADERS_VALUE;return config;}; }]);

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS