What are HTTP interceptors, and what are they used for?
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
- How do you call an API in Angular?
- What is an Observable, and how is it different from a Promise?
- What is the difference between subscribe and the async pipe?
- What are common RxJS operators you use, and what do they do?
- Explain the difference between switchMap, mergeMap, concatMap and exhaustMap.
- How do you handle errors from HTTP calls?