Http get request with header


#1

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!!


#2

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


#3

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?


#4

You didn’t answer my question:


#5

not getting your question?


#6

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


#7
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.