APIs

During this session I will introduce you to concept of APIs and hopefully will get you forever hooked on fetching data off the wild corners of the web and doing something cool with it. Also, ALL THE ACRONYMS

Table of contents

  1. Slides
  2. Why are APIs awesome
  3. HTTP requests
  4. What is JSON
  5. Parsing JSON responses
  6. Visual Twitter project
  7. Little bit more about AJAX

Slides

PDF version of the slides for this session can be found here.

Why are APIs awesome

APIs are the next generation’s cardboard box.

Give a child a cardboard box, and she’ll make a house, a rocket, a horse, a fort, a car, a cave, an oven, a container, a hat, and eventually a crumpled mess.

Give a developer an API, and she’ll make untold numbers of new forms of the functionality and content you’ve provided.

Webponce

HTTP requests

Remember we briefly talked about HTTP requests? Your browser makes them on your behalf every time you visit a webpage. But you don’t need to use a browser to make one and get data back

Here is a good article that can help you understand requests and their structure in a lot more detail. And here’s more on Wikipedia.

During the session I will show you what all this means in practice; we will use a tool called hurl.it to inspect them and understand how you can make them and what to do with the response you receive.

What is REST

Read a little bit more about REST architecture.

For now the most important is that you understand that there are different types of HTTP requests you can make.

GET

The GET command attempts to access the Web page and return the whole page, including the HTTP header. It does not attempt to return files associated with the page, such as images. (Source: IBM)

POST

The POST command attempts to access a Web page that contains an HTTP form and complete the fields of that form. (Source: IBM)

What is JSON

JSON stands for JavaScript Object Notation. It’s one of the formats you can get your data in from APIs. There are others, too, but we don’t have time to cover them. Not all of the APIs provide JSON-formatted responses, so you might have to read up on XML for example.

Parsing JSON responses

Hey, I bet when you open JSON in your browser it looks like shit a mess. You’re not the only one who struggles to see what is what that way! Install JSON View, a Chrome plugin that will display it nicely formatted for reading.

Visual Twitter project

We will get some tweets, and then fetch pictures from Flickr for each word of the tweet, to make Visual Twitter (similar to the Visual Dictionary).

Useful links for this little project:

Little bit more about AJAX

The Wikipedia article) explains it well. In a nutshell it’s a group of techniques that allow you to send and receive data without reloading the page (to put it very simply).