Trouble handling APIs

Trouble handling APIs
0

#1

I have been doing FCC challenges for around a month, and it was a pretty smooth journey so far. However, I have seemed to hit a roadblock, that I am unable to access APIs required to complete the intermediate projects due to cross domain restrictions and such. Of course, I have heard of ways to work around this like JSONP, and proxy sites but, to me, these don’t appear to be 100% reliable, or I have not come across some proper source which explains what exactly is this. This has made my experience in solving the projects really frustrating. I would appreciate links to proper documentation, or tutorials which explain exactly how JSON can be fetched cross-domain, preferably with real world examples.

Basically, if I were to end up developing an actual website which required access to APIs, what would be a step to step guide to accomplish this.


#2

In the real world, you’d be installing an SSL certificate on your own site… and/or you’d be paying for API premium services so they’ll let you connect via SSL (vs. the freebie account that may or may not let you connect via SSL)

For now, the solution is using (another freebie service, i.e. not 100% uptime) to connect to these API services.
https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather

The catch-22 problem happens when one API you need, for example, requires you to connect via SSL (ex: Google), and then another API service you use does not allow you to connect to their service via SSL (because you have a freebie account)

So using the cors-anywhere link above, you’re connecting to an https server, which then proxy calls for you to connect to the non-https API server.


#3

Thank you for your quick response. :slight_smile:
That actually explains a lot, I am fairly new to this whole concept, and your answer helped clear a lot of that. I had dug around the forums, and found another post with a similar problem, using the same solution you suggested, and it worked! This takes a huge load off my mind, I had been searching almost all day for a solution, thank you for helping out!