building api integrations you can live with

Post on 08-May-2015

224 Views

Category:

Internet

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

John Sheehan's talk from Future Insights Live 2014 in Las Vegas: "In this talk John will discuss strategies for debugging API problems, monitoring your dependencies so you can sleep at night and mitigating problems before they ruin your day." Miss his talk? Join us at a future show: www.futureofwebapps.com. Sign up for our newsletter at futureinsights.com and get 15% off your next conference.

TRANSCRIPT

John SheehanCEO, RunscopeRunscope

Building APIBuilding APIintegrations youintegrations youcan live with.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

Mobile &Desktop

Apps

Web Sites &Applications

Internal APIs

3rd-partyService APIs

Public APIs

Mobile &Desktop

Apps

Web Sites &Applications

Internal APIs

3rd-partyService APIs

Public APIs

fn(){}fn(){}

fn(){}

fn(){}fn(){}

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

YOUR APPLICATIONYOUR APPLICATION

What are the What are the challenges for runningchallenges for running

an API-drivenan API-drivenapplication?application?

CHALLENGE #1CHALLENGE #1

Getting a completepicture of your app.

Watch and logWatch and logeverythingeverything..

CHALLENGE #2CHALLENGE #2

Managingchange.

Prefer lighterabstractions.

Think twice aboutThink twice abouttaking a dependencytaking a dependency

on an SDK.on an SDK.

Your Code

The API

API SDK

v1v1

v2v2

Your Code

The API

API SDK

The API

API SDKHTTP Client v1

JSON Parser v1

Your Code

The API

API SDK

The API

API SDKHTTP Client

JSON Parser v1RequiresRequiresv1v1

RequiresRequiresv2v2

Your Code

The API

API SDK ??????

??????

SDKs OK:SDKs OK:Prototyping

No good HTTP ClientBuilding ClientsComplex APIs

Uses Native APIs

SDK DANGER:SDK DANGER:Using more than one

Community-builtMany dependencies

Inactive

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

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

HOW WE DOHOW WE DO

Smarter HTTP client

Thin wrappers

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"]

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

CHALLENGE #3CHALLENGE #3

High-fidelitytesting.

Let’s look at someAPI testing

frameworks.

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

mocky.iomocky.io

frisby.jsfrisby.js

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"]]

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

THANK YOUTHANK YOU

API Podcast:trafficandweather.iotrafficandweather.io

Try Runscope Free:runscope.comrunscope.com

top related