[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/common/http/HttpInterceptor [Back]  [Original]

HttpInterceptor Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/common/http

HttpInterceptor

interface
stable

Intercepts and handles an HttpRequest or HttpResponse.

HTTP GuideHttpInterceptorFn

On this page

    arrow_upward_alt Back to the top

    API

        
          interface HttpInterceptor {  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;}
        
        

    intercept

    Observable<HttpEvent<any>>

    Identifies and handles a given HTTP request.

    @paramreqHttpRequest<any>

    The outgoing request object to handle.

    @paramnextHttpHandler

    The next interceptor in the chain, or the backend if no interceptors remain in the chain.

    @returnsObservable<HttpEvent<any>>

    An observable of the event stream.

    Description

    Intercepts and handles an HttpRequest or HttpResponse.

    Most interceptors transform the outgoing request before passing it to the next interceptor in the chain, by calling next.handle(transformedReq). An interceptor may transform the response event stream as well, by applying additional RxJS operators on the stream returned by next.handle().

    More rarely, an interceptor may handle the request entirely, and compose a new event stream instead of invoking next.handle(). This is an acceptable behavior, but keep in mind that further interceptors will be skipped entirely.

    It is also rare but valid for an interceptor to return multiple responses on the event stream for a single request.

    Usage Notes

    To use the same instance of HttpInterceptors for the entire app, import the HttpClientModule only in your AppModule, and add the interceptors to the root application injector. If you import HttpClientModule multiple times across different modules (for example, in lazy loading modules), each import creates a new copy of the HttpClientModule, which overwrites the interceptors provided in the root module.

    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page