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 http://en.wikipedia.org/wiki/Api, 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!"

http://www.leafly.com/explore

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: http://www.leafly.com/api/strains

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.
[{
    "Key":"afghan-kush",
    "Name":"Afghan Kush",
    "Category":"Indica",
    "Symbol":"Afg",
    "Abstract":"Originating from the Hindu Kush mountains of Afghanistan...",
    "Url":"http://www.leafly.com/indica/afghan-kush",
    "DetailUrl":"http://www.leafly.com/api/details/afghan-kush",
    "Rating":8,
    "TopEffect":"Lazy",
    "TopMedical":"Migraines",
    "TopActivity":"Relax at home"},
    {
    "Key":"ak-47",
    "Name":"AK-47",
    "Category":"Hybrid",
    "Symbol":"Ak",
    "Abstract":"A great afghani kush cannabis strain that is mostly sativa...",
    "Url":"http://www.leafly.com/hybrid/ak-47",
    "DetailUrl":,"http://www.leafly.com/api/details/ak-47
    "Rating":7,
    "TopEffect":"Lazy",
    "TopMedical":"Migraines",
    "TopActivity":"Relax at home"
}]


No comments:

Post a Comment