Power of APIs – Why APIs? – Let's talk about the Internet



Power of APIs – Why APIs? – Let's talk about the Internet

0 0


power-of-apis

Slide deck for a workshop introducing APIs and principles of the web (HTTP + REST).

On Github ktzhu / power-of-apis

Power of APIs

Ask and you shall receive.

JOUR 390 | Spring 2013

Katie Zhu +@ktzhu

What is an API?

Application Programming Interface.

Why APIs?

Pull in outside data

Send messages

Connect to other services (Facebook, Twitter)

Powerful, dynamic apps.

Overview

More specifically, today we'll cover:

The Internet – what is it

HTTP

Client + server model

REST easy

RESTful APIs

Requests

Prework

How'd it go?

Technical concerns, too hard? Chat also about some ideas for using APIs in their projects.

Let's talk about the Internet

What happens when you type this into your browser?

Name gets translated to IP address (involves your computer, the client, talking to a server).

After IP address gets resolved, your browser goes to eecs.northwestern.edu to request the files for the webpage.

Extremely simplified, but this leads us to ...

http

HyperText Transfer Protocol

Basically, rules that govern how content gets from one place to another in the depths of the intertubez.

We use HTTP to get pages on the Internet. Where do these pages come from?

YOU GUESSED IT, THE INTERNET.

But actually, other computers on the Internet: servers.

Try it yourself:

                                            
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/", false);
xhr.send();

console.log(xhr.status);
console.log(xhr.statusText);
                                            
                                            

Client + Server

The Internet is full of clients. They want a lot of things.

(things = web pages, files, scripts, images, audio, video ...)

Servers store this information and will send a response back to you.

Request + Response

HTTP is kind of like the social conventions for talking on the web.

Request: Ask and you shall receive.

Response: A good server will acknowledge your request.

REST easy

Representational State Transfer.

REST easy

All you need to know: set of principles around the existence of resources [anything URI addressable] and manipulation of those resources.

HTTP is built on REST principles. Most web APIs are also designed to be RESTful (adhering to REST principles).

REST easy

When you (client) are on a website, and you click that link to a chill sloth gif, you are, in REST terms, making a state transition.

The server then processes this request, returns the appropriate resources to you.

Okay so why do I care?

APIs! That's why you're here, right?

RESTful APIs

APIs: think of as a ~~~*~code contract~~*~ that says how programs can interact with a given application or service.

Let's say you wanted get all the tweets hashtagged with #boston. You would need to use Twitter's API, which specifies how you authenticate (login), which URLs you go to get the data, and so forth.

We call an API "RESTful" if it does the following:

  • Separate client and server.
  • Don't hold state between requests (you can get everything you need in one request).
  • Use HTTP + HTTP methods.

Resources

IFTTT

API Hub

Codecademy

Google + API documentation.

RESTful web APIs

Thanks!

Any questions?