Read Custom HTTP Headers Sent by the Server in Angular

Share this video with your friends

Send Tweet

By default the response body doesn’t contain all the data that might be needed in your app. Your server might return some special header which you have to read explicitly. In such case we can use the { observe: ‘response’} configuration of the Angular HttpClient. Let’s explore how.

Kian
~ 6 years ago

Having problems accessing the local API. I found the code here https://github.com/eggheadio-projects/egghead-learn-http-in-angular/tree/read-custom-headers and tried to run it but I get an error after clicking on the Fetch people button: GET http://localhost:4200/api/v1/people 426 (Upgrade Required). Going to the API URL directly works eg http://localhost:3000/api/v1/people

Any suggestions?

Juri Strumpflohnerinstructor
~ 6 years ago

Hey Kian. I'll check this out (currently not on my computer) and reach out to you again.

Juri Strumpflohnerinstructor
~ 6 years ago

Hey Kian. I just tried to download the repo and run the example using "npm start" and it worked just fine. Just for reference, I used npm v5.6.0, node v9.11.1 (should also work with a lower version) and the latest Chrome.

Let me know if the problem persists.

Kian
~ 6 years ago

Hi Juri, Thanks for your response and suggestions. The problem is still present on my work PC, after upgrading node and npm. However, I did try it on my home computer and it worked no problem.

~ 6 years ago