top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

What is an interceptor? What are common uses of it?

0 votes
What is an interceptor? What are common uses of it?
posted Jan 24, 2017 by Manisha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Interceptors act as a hook up for the HTTP calls.
The $httpProvider provider contains an array of interceptors. An interceptor is simply a regular service factory that is registered to that array.
The following code shows how to create intercepters

module.factory('myInterceptor', ['$log', function($log) {  
        $log.debug('$log is here to show you that this is a regular factory with injection');

        var myInterceptor = {
            return myInterceptor;

Injectors are primarily used in adding custom logic for authentication, authorization, session/state management, logging, modifying Response, URL rewriting, Error handling, Caching, adding custom header, timestamp in the request /response, encrypt and decrypt the request and response information or manipulate the request and response data over the request cycles.

answer Jan 30, 2017 by Ranjith Havaldar
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.