FCC's JavaScript Weather App: Introduction to API's

The Goal: To create an app that takes weather data from a weather information site and display it to a site so that any user can get their local weather data (in Celsius and Fahrenheit) from my app. Here's an example of my end goal.

As part of my goal to become really good at JavaScript and Java, I've started to take on projects on Free Code Camp again. This project required me to find a good API or Application Programming Interface. What is an Application Programming Interface? Interface is just a fancy word for a meeting ground of two organizations or systems. So an Application Programming Interface is a sort of meeting ground for one application to retrieve data from another application. This is important because, generally speaking, there are two ways to obtain data. One way landed me in trouble with a web admin and is incredibly slow and tedious and generally not allowed. That is to scrape the data off a website with a web crawler. The other is to use an API. Use API's. Its a skills employers need and its what developers have set up (with certain conditions such as a payment or providing credit to the data they have obtained) so that you can safely and securely obtain valuable information.

With JavaScript, an API returns an object in JSON form. Here is an example from my project's api call that was printed to the console.


 This is a pretty sweet deal and I must provide credit to the best weather API that is both simple and easy to use: Weather Underground. So how can we make this object useful to our application? The default language of data transmission on the web is JSON (which is why JavaScript is popular). This means that with an API call with jQuery (outlined next post) that I can simply pull data from this object with a command such as (object name).current_observation.UV. Any guess what data this would return? It would return the integer value of 3, where (object name) is the name of a local variable. This might be a little cloudy now, but I plan on outlining how this works exactly in my next post. Get it? Cloudy?! Weather??? Alright, till next time...

No comments:

Post a Comment