O'Reilly logo

Mastering Web Application Development with AngularJS by Pawel Kozlowski, Peter Bacon Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using advanced features of $http

The $http service is extremely flexible and powerful. Its super-powers are result of clean, flexible API and usage of the Promise API. In this section, we are going to see how we can use some of the more advanced features of the $http service.

Intercepting responses

AngularJS built-in $http service allows us to register interceptors that will be executed around each and every request. Such interceptors are very useful in situations where we need to do special processing for many (potentially all) requests.

As the initial example, let's assume that we want to retry failed requests. To do so we can define an interceptor that inspects response status codes and retries a request, if the HTTP Service Unavailable (503) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required