Transcript
Page 1: Building API Integrations You Can Live With

John SheehanCEO, RunscopeRunscope

Building APIBuilding APIintegrations youintegrations youcan live with.can live with.

Page 2: Building API Integrations You Can Live With

“ ”There's just no getting around it: you're building a you're building a distributed systemdistributed system.

-- Mark Cavage, ACM Queue

Page 3: Building API Integrations You Can Live With

Mobile &Desktop

Apps

Web Sites &Applications

Internal APIs

3rd-partyService APIs

Public APIs

Page 4: Building API Integrations You Can Live With

Mobile &Desktop

Apps

Web Sites &Applications

Internal APIs

3rd-partyService APIs

Public APIs

fn(){}fn(){}

fn(){}

fn(){}fn(){}

Page 5: Building API Integrations You Can Live With

fn(){} fn(){}fn(){}fn(){} fn(){}

YOUR APPLICATIONYOUR APPLICATION

Page 6: Building API Integrations You Can Live With

What are the What are the challenges for runningchallenges for running

an API-drivenan API-drivenapplication?application?

Page 7: Building API Integrations You Can Live With

CHALLENGE #1CHALLENGE #1

Getting a completepicture of your app.

Page 8: Building API Integrations You Can Live With

Watch and logWatch and logeverythingeverything..

Page 9: Building API Integrations You Can Live With

CHALLENGE #2CHALLENGE #2

Managingchange.

Page 10: Building API Integrations You Can Live With

Prefer lighterabstractions.

Page 11: Building API Integrations You Can Live With

Think twice aboutThink twice abouttaking a dependencytaking a dependency

on an SDK.on an SDK.

Page 12: Building API Integrations You Can Live With

Your Code

The API

API SDK

v1v1

v2v2

Page 13: Building API Integrations You Can Live With

Your Code

The API

API SDK

The API

API SDKHTTP Client v1

JSON Parser v1

Page 14: Building API Integrations You Can Live With

Your Code

The API

API SDK

The API

API SDKHTTP Client

JSON Parser v1RequiresRequiresv1v1

RequiresRequiresv2v2

Page 15: Building API Integrations You Can Live With

Your Code

The API

API SDK ??????

??????

Page 16: Building API Integrations You Can Live With

SDKs OK:SDKs OK:Prototyping

No good HTTP ClientBuilding ClientsComplex APIs

Uses Native APIs

Page 17: Building API Integrations You Can Live With

SDK DANGER:SDK DANGER:Using more than one

Community-builtMany dependencies

Inactive

Page 18: Building API Integrations You Can Live With

SDK FOR PROVIDERS:SDK FOR PROVIDERS:Definitely build them!...for many platforms

...as native as possible...and well-documented

Page 19: Building API Integrations You Can Live With

HOW WE DOHOW WE DO

Smarter HTTP client

Thin wrappers

Page 20: Building API Integrations You Can Live With

url = "https://ec2-23-212-199-23.us-west-2.amazonaws.com"resp = requests.get(url)if resp.ok: return resp.json()else:# retry? return None

def get_user(id):

def main(): user = get_user(id) print user["name"]

Page 21: Building API Integrations You Can Live With

class Identity def get_user(id): url = "service://identity/users/" + id resp = smart_client.get(url) if resp.ok: return User(resp.json())

return AnonymousUser()

from Identity import get_user

def main():user = get_user(id)print user.name Auto-Auto-

locatelocateserviceservice

SmartSmartretriesretries

Page 22: Building API Integrations You Can Live With

CHALLENGE #3CHALLENGE #3

High-fidelitytesting.

Page 23: Building API Integrations You Can Live With

Let’s look at someAPI testing

frameworks.

Page 24: Building API Integrations You Can Live With

require&'rubygems'require&'test/unit'require&'vcr'VCR.configure&do&|c|&c.cassette_library_dir&=&'fixtures/vcr_cassettes'&c.hook_into&:webmock&#"or":fakewebendclass&VCRTest&<&Test::Unit::TestCase&def&test_example_dot_com&&&VCR.use_cassette('synopsis')&do888888url&=&'http://yourapihere.com'&&&&&response&=&Net::HTTP.get_response(URI(url))&&&&&assert_match&/Example&domains/,&response.body&&&end&endend

VCR VCR github.com/vcr/vcr

Page 25: Building API Integrations You Can Live With

mocky.iomocky.io

Page 26: Building API Integrations You Can Live With

frisby.jsfrisby.js

Page 27: Building API Integrations You Can Live With

aspec aspec github.com/songkick/aspec

# no users have pending notifications GET /users/with-pending-notifications 200 application/json []

# users with events on their calendar have pending notifications POST /users/764/metro-areas/999 204 POST /users/764/artists/123 204 POST /events/5?artist_ids=123&metro_area_id=999 204 POST /events/5/enqueue-notifications 204 GET /users/with-pending-notifications 200 application/json [[764, "ep"]]

# users are unique in the response POST /users/764/artists/123 204 POST /users/764/artists/456 204 POST /users/764/metro-areas/999 204 POST /events/5?artist_ids=123,456&metro_area_id=999 204 POST /events/5/enqueue-notifications 204 GET /users/with-pending-notifications 200 application/json [[764, "ep"]]

Page 28: Building API Integrations You Can Live With

service'"http://localhost:4567"'do'def'responds_with_json_where'''JSON.parse(response.body)'end'resource'"/lolz"'do'''get'do'''''it'{'responds_with.status':ok'}'''''it'{'responds_with_json_where['lolz'].must_be_instance_of'Array'''''with_query("q=monorail")'do'''''''it'"only'lists'lolz'that'match'the'query"'do'''''''''responds_with_json_where['lolz'].wont_be_empty'''''''''responds_with_json_where['lolz'].each'do'|lol|'''''''''''lol['title'].must_match'/monorail/'''''''''end'''''''end'''''end'''''with_query("q=looong")'do

HyperSpecHyperSpec

Page 29: Building API Integrations You Can Live With
Page 30: Building API Integrations You Can Live With

THANK YOUTHANK YOU

API Podcast:trafficandweather.iotrafficandweather.io

Try Runscope Free:runscope.comrunscope.com


Recommended