There’s An API for That

If you’re using the web, you’re almost certainly already using an API on some site. But what is an API, exactly? The acronym for Application Program Interface doesn’t exactly set a lightbulb off does it? In fact, it sounds kind of cold and distant like your mother in law. Well APIs are way cooler than your mother in law and after struggling with using them as super noob I’m here to spread the gospel.

You see, big companies like YouTube, Instagram, Spotify and Google have a lot of data at their disposal. So much data in fact. But, much of that information they’d rather not share with you, like the whereabouts of their secret underground labs and users passwords and whatnot; this is where APIs come in. A company with all this data still wants to share some with you, the developer to make cool stuff and ultimately drive more people to interact and add to their data so they create some web services that allow you to interact with data playing by their rules.

For example, many local governments are creating APIs for developers to take their data and do something useful like pinpoint wifi hotspots in the city or access police records. They offer a set of parameters that reach certain endpoints to look at data but won’t let you run willy nilly on their datasets by looking up the home of officer Jenkins, the guy who gave you a parking ticket last month.

APIs typically allow the transfer of data over HTTP requests which use REST or Representational State Transfer… this is a loaded acronym for a complex architecture that most APIs rely on but I’ll attempt an explanation: Using an API will most likely require a URL like the address for a website to request the information. You, as the client, make a request to the server (URL) using whatever parameters are necessary and it returns data that you can render in the form of HTML. Not only can you GET data, but you can PUT (create data) POST (update data) and DELETE (you can figure that one out) as well. Here’s an example:

$.ajax({
url: “https://data.sfgov.org/resource/gxxq-x39z.json?pddistrict=MISSION&dayofweek=Friday&$order=date DESC&$where=date>’2016-01-01T12:00:00′”,
dataType: “json”,
success: function(data) {
console.log(data)

}

The bit of code above is using Jquery’s AJAX (Asynchronous JavaScript and XML … don’t worry about that) method to get data from the URL. Go ahead and copy the URL (not the quotes) into your browser and see what you get. Better yet, don’t be lame and get PostMan for your Chrome Browser which let’s you run sweet http requests and see the data all prettified without having to go through the trouble of running an AJAX request and logging the data to your console to see what your working with.

That’s great that I’ve got this data you say… but what the hell am I supposed to do with it?

Well, we will explore just that in the next post. Check out an API or two in the meantime and run them in PostMan to see what kind of sweet raw data you’ll get. Don’t be lame.

 

3 thoughts on “There’s An API for That

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s