From 198e84156458f8b88f524751ca0fa89f2eadea64 Mon Sep 17 00:00:00 2001 From: Aristeidis Bampakos Date: Wed, 2 Dec 2020 23:25:58 +0200 Subject: [PATCH] docs(http): add example for interceptor order (#39938) Add an example for the order of interceptor with image PR Close #39938 --- aio/content/guide/http.md | 16 +++++- .../images/guide/http/interceptor-order.svg | 50 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 aio/content/images/guide/http/interceptor-order.svg diff --git a/aio/content/guide/http.md b/aio/content/guide/http.md index e261b3451a..e4f52097d7 100644 --- a/aio/content/guide/http.md +++ b/aio/content/guide/http.md @@ -653,8 +653,20 @@ There are many more interceptors in the complete sample code. ### Interceptor order Angular applies interceptors in the order that you provide them. -If you provide interceptors _A_, then _B_, then _C_, requests flow in _A->B->C_ and -responses flow out _C->B->A_. +For example, consider a situation in which you want to handle the authentication of your HTTP requests and log them before sending them to a server. To accomplish this task, you could provide an `AuthInterceptor` service and then a `LoggingInterceptor` service. +Outgoing requests would flow from the `AuthInterceptor` to the `LoggingInterceptor`. +Responses from these requests would flow in the other direction, from `LoggingInterceptor` back to `AuthInterceptor`. +The following is a visual representation of the process: + + + +
+ + The last interceptor in the process is always the `HttpBackend` that handles communication with the server. + +
You cannot change the order or remove interceptors later. If you need to enable and disable an interceptor dynamically, you'll have to build that capability into the interceptor itself. diff --git a/aio/content/images/guide/http/interceptor-order.svg b/aio/content/images/guide/http/interceptor-order.svg new file mode 100644 index 0000000000..e85d2a6f48 --- /dev/null +++ b/aio/content/images/guide/http/interceptor-order.svg @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + HttpClient + + + + AuthInterceptor + + + + LoggingInterceptor + + + + HttpBackend + + + + Server + + +