Advanced AngularLesson 36Free preview
Angular HTTP Interceptors
This lesson is part of Angular · All levels
Summary
The interceptor allows you to modify any HTTP request or response in one place, such as adding an authentication token or handling an error 401. Modern angular uses interceptors as functions listed through provideHttpClient(withInterceptors()). This approach is much more concise than the old class of interceptors.
Key points
- The functional interceptor is written as HttpInterceptorFn
- Register by provideHttpClient(withInterceptors([...]))
- SetHeaders add header like Authorization
- Global error messages can be handled in the response interceptor.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.