Over a million developers have joined DZone.

AngularJs Interceptor - Example

DZone's Guide to

AngularJs Interceptor - Example

· DevOps Zone ·
Free Resource

Learn more about how CareerBuilder was able to resolve customer issues 5x faster by using Scalyr, the fastest log management tool on the market. 

Here I will explain an angularjs interceptor to get application context path for every http request.

angular.module('app').factory('PathInterceptor', ['$location',function($location) {  
    var path = {
        request: function(config) {
        	var path = $location.absUrl(); 
            var pathArray = path.split('/');
            var appContext = pathArray[3];
        	config.url = "/"+appContext+config.url;
            return config;
        response: function(response) {
            return response;
    return path;

angular.module('app').config(['$httpProvider', function($httpProvider) {  

We are using angularjs $location service to get the context path and modify the http request.

Find out more about how Scalyr built a proprietary database that does not use text indexing for their log management tool.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}