Search code examples
angular5angular-httpclient

How to Reading the full response header using Angular 5 HttpClient


I have written service in Angular 5 which does a GET request to my backend using the HttpClient class.

My request looks like this:

headers =  new HttpHeaders().set('Content-Type', 'application/json')
                             .set('X-XSRF-TOKEN', 'sdfhjsdgh');

          const options = ({ headers: headers});
          this.http.get('http://127.0.0.1:8080/api/v1/display', options)
         .filter(data => data.status === 200 || data.status === 206)
         .map((res) => this.success(res))
         .catch((res) => this.failure(res, service));

How do I use response header? so I can check status code and all that.

Any help is very much appreciated.


Solution

  • headers =  new HttpHeaders().set('Content-Type', 'application/json')
                             .set('X-XSRF-TOKEN', 'sdfhjsdgh');
    
          this.http.get('http://127.0.0.1:8080/api/v1/display', {
            headers: headers,
            params: params,
            observe: 'response'})
         .filter(data => data.status === 200 || data.status === 206)
         .map((res) => this.success(res))
         .catch((res) => this.failure(res, service));