Monday, July 29, 2013

Introduction to APIs

An important part of almost every web app is reading, parsing, and selecting data.

The process of doing this with a public API, can be a simple task.

Okay, hold on now, what's an API?

First, I's say do a quick read through of, but if TL;DR...

An API is an Application Programming Interface, which in simple terms is both a collection of data and commonly a means of manipulating it.

An easy way to think about APIs is that they are an interface that unifies how applications communicate with other applications.

So let's try accessing Leafly's wonderful API strain collection.

"Let's talk to the data!"

That's a good view of some of the data that's available to access.

Now here's a view of what it looks like to your code which will process it:

Well, that's clearly more convoluted... So whats really going on here?

If you took some of that and nicely spaced it out, these are what you would be left with.
    "Name":"Afghan Kush",
    "Abstract":"Originating from the Hindu Kush mountains of Afghanistan...",
    "TopActivity":"Relax at home"},
    "Abstract":"A great afghani kush cannabis strain that is mostly sativa...",
    "TopActivity":"Relax at home"