What are HTTP interceptors, and what are they used for?

Angular HTTP, RxJS and state · Freshers and experienced

Model answer

An interceptor sits between your code and the network. It can change every outgoing request or incoming response. Typical uses: adding an authorization header, showing a global loading indicator, handling 401 errors by redirecting to login, retrying, and logging.

In current Angular, interceptors are functions registered with provideHttpClient(withInterceptors([authInterceptor])). Be careful not to send tokens to third-party domains, and avoid refresh-token loops by handling the refresh call separately.

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions