ottz0
ottz0

Reputation: 2605

Connecting to an external API with Angular

I'm trying to connect to the Expedia Api. With this they have an api key and id.

I was using jsonp with this but there is a bug in there causing problems. The other thing is my api key is exposed in the javascript.

So now I have to find another way. I am now requesting json but of course I can't get cross domain with it so I have found a php proxy. My app is now reliant on php (this is ok though). When I access the php proxy I now get authentication errors. I have tried a different endpoint on a different site and the script works.

So therefore I cannot access this API.

There seems to be very little information, tutorials and scripts out there on how to make an api cross site, php proxies or authentication. I thought with the amount of sites now reliant on this type of technology there might be something.

How can I make a php proxy and return this data back to angular? How can I safely hide my api key?

Upvotes: 1

Views: 214

Answers (1)

Mat Taylor
Mat Taylor

Reputation: 191

Have all of your API keys etc in a PHP file on your server. In that PHP file you need to curl to the API. Then have your PHP script return a json_encode() of whatever their API returns. That way no one sees your API deets.

Upvotes: 1

Related Questions