Over a million developers have joined DZone.

AngularJs Interceptor - Example

DZone's Guide to

AngularJs Interceptor - Example

· DevOps Zone ·
Free Resource

Is the concept of adopting a continuous everything model a daunting task for your fast moving business? Read this whitepaper to break down and understand one of the key pillars of this model in Continuous Governance: The Guardrails for Continuous Everything.

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.

Are you looking for greater insight into your software development value stream? Check out this whitepaper: DevOps Performance: The Importance of Measuring Throughput and Stability to see how CloudBees DevOptics can give you the visibility to improve your continuous delivery process.


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}