CodeZettaInterview Hub

Angular · Interceptors · Mid-Level · Best Practice

What is an HttpInterceptor?

Short Interview Answer

Middleware that transforms requests/responses globally (auth headers, logging, errors).

Detailed Explanation

Functional interceptors with provideHttpClient(withInterceptors([...])) are modern. Order matters. Always clone requests when modifying.

Example

export const authInterceptor: HttpInterceptorFn = (req, next) => {
  const token = inject(Auth).token;
  return next(req.clone({ setHeaders: { Authorization: `Bearer ${token}` } }));
};

Did you know this answer?