Http get request with header

baseUrl = ‘https://developers.zomato.com/api/v2.1/search?entity_id=5&entity_type=city&sort=cost&order=asc’;

headers :{ ‘user-key’ : ‘0c3b1b0774975e0280290d78aae415ec’ }

i’m trying

this.http.get(baseUrl, headers).map(res => res.json());

but not working how do I suppose to write get data?

Thanks in advance!!

“Not working” conveys very little information. What is going over the wire in each direction?

How to pass header in HTTP.GET scenario
while url: ‘https://developers.zomato.com/api/v2.1/search?entity_id=5&entity_type=city&sort=cost&order=asc’;
and header is { ‘user-key’ : ‘0c3b1b0774975e0280290d78aae415ec’ }

how should i create get request?

You didn’t answer my question:

not getting your question?

What does your code request from the server and what does the server respond to it right now?

let endPoint = 'https://developers.zomato.com/api/v2.1/search?entity_id=5&entity_type=city&sort=cost&order=asc';
let headersObj = new Headers({'user-key':'0c3b1b0774975e0280290d78aae415ec'});

this.http.get(endPoint, {headers:headersObj}).map(res => {
      console.log('res',res);
      if (res.status < 200 || res.status > 300) {
        throw new Error("Error in your code with status" + res.status);
      }
      return res.json()
    }).catch(this.handleError);

I hope this will help you getting your issue solved.

2 Likes