Search code examples
httphttpclientangular-http-interceptors

Skip requests from HTTP Interceptors for login request


I have an angular application which intercepts all outgoing requests with HTTP Interceptor to add authentication token to the request. I dont want this for the login request. So that i have been using http module for this. How can I use httpClientModule for this purpose without intercepting with the HTTP Interceptor?


Solution

  • Use HttpBackend which will dispatch the request via browser HTTP APIs directly to the backend, without going through the interceptor chain.

    import { HttpBackend, HttpClient } from '@angular/common/http';
    
      constructor(private httpClient: HttpClient, handler: HttpBackend) {
        this.httpClient = new HttpClient(handler);
      }
    

    Then, use this instance of httpClient for REST.