21
Getting Started With Public APIs Eryn O’Neil @eryno

Getting Started with Public APIs

Embed Size (px)

Citation preview

Page 1: Getting Started with Public APIs

Getting Started With Public APIs

Eryn O’Neil • @eryno

Page 2: Getting Started with Public APIs

Today’s Agenda● Evaluating an API● Authentication● Testing (“Hello, API!”)● Now What?

Page 3: Getting Started with Public APIs

Today’s (and Forever’s) Ground Rules:● If you don’t understand: Ask.● No, really. Ask! No dumb questions.● If you get too into the weeds, I might cut you off.

But err on the side of asking.

Page 4: Getting Started with Public APIs

Most important ground rule:

Don’t be afraid to start slow and enjoy yourself.

So you don’t know how OAuth works. So what? You don’t need to yet.

You aren’t less of a programmer if you abstract away the complicated parts or don’t know what “endpoint” means. (It’s just a fancy word for “URL”, anyway).

We all start somewhere.

Page 5: Getting Started with Public APIs

Evaluating an APIOr: Um, which one should I pick?

Page 6: Getting Started with Public APIs

Where should I start?

Prioritize ease of use over popularity.

Page 7: Getting Started with Public APIs

Reasonable Approaches● Flickr● Last.fm● Twilio● Lots and lots of other sites

There Be Dragons● Twitter● Facebook

Page 8: Getting Started with Public APIs

Evaluating an API: Documentation

Page 9: Getting Started with Public APIs

Evaluating an API: Documentation

Page 10: Getting Started with Public APIs

AuthenticationOr: “I promise I’m me” isn’t good enough for you?

Page 11: Getting Started with Public APIs

AuthenticationAuthentication can be hard to

implement well. Fortunately, you aren’t implementing it.

Common methods:

● No authentication● HTTP Basic Authentication● HMAC● OAuth / OAuth2

Page 12: Getting Started with Public APIs

Authentication: None!Not very common, because it’s harder to limit abuse.

But if you find one, they make a great place to learn your tools.

Keep APIs available with one weird trick: Don’t be a jerk.

Example: http://jsonplaceholder.typicode.com/

Page 13: Getting Started with Public APIs

Authentication: HTTP Basic AuthenticationHTTP Basic Auth is as old as the internet and baked into every web browser. It’s not the most secure method, but it is very convenient.

How it works:

1. Get a username and password2. Base64 encode the string “username:password”3. Pass the base64-encoded string as an HTTP header named Authorization.

4. Done.

Page 14: Getting Started with Public APIs

Authentication: HTTP Basic AuthenticationPractically speaking…

1. Use PHP:

2. Send it in the URL:

http://username:[email protected]/

3. Use Postman.

Page 15: Getting Started with Public APIs

“Um, what’s Postman?”I’m so glad you asked.

https://www.getpostman.com/

Page 16: Getting Started with Public APIs

Authentication: HMAC & OAuthHMAC = [keyed-]Hash Message Authentication Code

A pre-agreed upon way of hashing several pieces of data-- usually a username, a secret key or password, the request being made (URL), and something that changes every request (like a timestamp).

OAuth isn’t an acronym, but it basically means “Open Authentication”

An implementation of HMAC, plus a standard script for HTTP calls that allows a client (ex: you) to authenticate against a server (ex: Twitter) asynchronously.

Page 17: Getting Started with Public APIs

Authentication: HMAC & OAuthThey’re both great, but they’re a little complicated to describe in this talk.

One day you may write an OAuth server or client. That will be a great time to learn more about it.

Until then: Use the magic OAuth button in Postman.

Page 18: Getting Started with Public APIs

Okay, I got my instant gratification. I need more than Postman. Now what?

Write something!Slim: http://www.slimframework.com/

Page 19: Getting Started with Public APIs

PossibilitiesDownload listening data from Last.fm and find out how many people are both Metallica fans and One Direction fans.

Write a script that auto-rejects LinkedIn requests for every recruiter that emails you with a job that has nothing to do with your skills.

Automatically pull every cat photo from Flickr and change your desktop every 15 minutes. (You won’t get through every cat photo, but if you try to do it in real time you’ll probably freeze your machine.)

Page 20: Getting Started with Public APIs

I hate those ideas.Where can I find more?

http://www.programmableweb.com/apis/directory

Page 21: Getting Started with Public APIs

So, what are you going to build?(Thanks!)