Top Banner
I <3 APIs San Jose, October 2015 API first? @mikermcneil
68

I Love APIs - Oct 2015

Feb 11, 2017

Download

Technology

Mike McNeil
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: I Love APIs - Oct 2015

I <3 APIsSan Jose, October 2015

API first?

@mikermcneil

Page 2: I Love APIs - Oct 2015

API first?

©2015 Apigee Corp. All Rights Reserved.

The views expressed in this presentation are those of the presenter, and not necessarily those of Apigee Corporation or the presenter’s employer.

1

Page 3: I Love APIs - Oct 2015

Mike McNeil

@mikermcneilgithub.com/mikermcneil

Page 4: I Love APIs - Oct 2015

Mike McNeil

Founder/CEO Treeline (YC W15)

creator & BDFL of

Page 5: I Love APIs - Oct 2015

the leading open-source MVC framework for Node.js

Page 6: I Love APIs - Oct 2015

demo

For a deeper dive, google: “Sails.js Platzi”

Page 7: I Love APIs - Oct 2015

1. No REST For The Weary 2. Upside Down 3. Everyday APIs

Page 8: I Love APIs - Oct 2015

RESTNo

for the weary.

1.

Page 9: I Love APIs - Oct 2015

A good starting point for building any cloud API.

REST

Page 10: I Love APIs - Oct 2015

REST CRUD===

For our purposes:

Page 11: I Love APIs - Oct 2015

Create Read Update Delete

Page 12: I Love APIs - Oct 2015

first version (late 2011)

Page 13: I Love APIs - Oct 2015
Page 14: I Love APIs - Oct 2015

custom app-specific adapters(LDAP / Active Directory / etc)

~20 other community adapters

Page 15: I Love APIs - Oct 2015
Page 16: I Love APIs - Oct 2015

A noun-centric ontology works great for building

databases.

Page 17: I Love APIs - Oct 2015

Never works for 100% of any app.

CRUD

Page 18: I Love APIs - Oct 2015

Search the store.

Page 19: I Love APIs - Oct 2015

search({      query:  ‘shoes’  });

Search the store.

Page 20: I Love APIs - Oct 2015

Product.find({      or:  [          {  name:  {contains:  ’shoes’}},          {  description:  {contains:  ’shoes’}}      ]  });

//  …also  search  recipes

//  …also  search  comments  then  for  each  one,  look  up  //  the  containing  product  or  recipe…

Search the store.

//  …then  rank  results..  oh  wait  but  actually  this  should  all  be  in  an  index  of  some  kind

Page 21: I Love APIs - Oct 2015

Log in.

Page 22: I Love APIs - Oct 2015

login({      username:  ‘mikermcneil’      password:  ‘c4tP4rTy’  });

Log in.

Page 23: I Love APIs - Oct 2015

Session.create({      userId:  User.find({          username:’mikermcneil’          password:  ‘c4tP4rTy      }).id  })

Log in.

Page 24: I Love APIs - Oct 2015

So do we use CRUD?

Page 25: I Love APIs - Oct 2015

Because half the time, we don’t actually know what

we’re supposed to be building.

Page 26: I Love APIs - Oct 2015

2. Upside Down

Page 27: I Love APIs - Oct 2015

API first?

Page 28: I Love APIs - Oct 2015

API first? API centric, UI first.

Page 29: I Love APIs - Oct 2015

We need to flip things upside down

Page 30: I Love APIs - Oct 2015

write automated tests for code

write documentation for codewrite code

manually test code deploy code to server

discover bug

remember how code works

fix code

manually test code

discover that automated tests fail now

update automated tests

update documentation redeploy code to server

design

Page 31: I Love APIs - Oct 2015

write automated tests for code

write documentation for codewrite code

manually test code deploy code to server

discover bug

remember how code works

fix code

manually test code

discover that automated tests fail now

update automated tests

update documentation redeploy code to server

design

Page 32: I Love APIs - Oct 2015

How we think as product designers:

1. User interface design 2. Interaction design 3. Cross fingers (development starts) … 4. Oh crap, one more thing I forgot to mention… 5. Can I see a preview? 6. AHHH WHAT IS THIS?!

Page 33: I Love APIs - Oct 2015

“Traditional” Development Process

1.Design data model 2.Implement custom server code 3.Start implementing custom UI code

c. 2005

Page 34: I Love APIs - Oct 2015

“Traditional” Development Process

1.Design data model 2.Implement custom server code 3.Start implementing custom UI code 4.AHHHHHHH WTF IS THIS??! 5.Change the data model, change server code, change UI

code, change API docs (but you probably don’t have any)

c. 2005

Page 35: I Love APIs - Oct 2015

“NoSQL” Development Process

1.Implement custom server code 2.Implement custom UI code 3.Stumble upon (then maybe even document!)

your cloud API 4.Stumble upon your data model

c. 2011

Page 36: I Love APIs - Oct 2015

“NoSQL” Development Process

1.Implement custom server code 2.Implement custom UI code 3.AHHHHHHH WTF IS THIS??! 4.Change server code, change UI code 5.Stumble upon & document your cloud API 6.Stumble upon your data model

c. 2011

Page 37: I Love APIs - Oct 2015

“API-Centric” Development Process

1.Implement custom code for each UI 2.Implement fake server code 3.Stumble upon your cloud API 4.Implement real server code 5.Stumble upon your data model

Page 38: I Love APIs - Oct 2015

“API-Centric” Development Process

1.Implement custom code for each UI 2.Implement fake server code 3.AHHHHHHH WTF IS THIS??! (one or more of the UIs changed) 4.Change UI code 5.Stumble upon your cloud API 6.Now implement real server code 7.Stumble upon your data model

Page 39: I Love APIs - Oct 2015

Goal: Minimize technical debt, code changes, and rewrites.

How: Show stakeholders and customers the developing or fully-implemented UI as early as possible.

Page 40: I Love APIs - Oct 2015

It’s ok if the backend starts off… fake.

Page 41: I Love APIs - Oct 2015

3. Everyday APIs

Page 42: I Love APIs - Oct 2015

We don’t design most of the APIs we use.

Page 43: I Love APIs - Oct 2015

Human

Client Devices

Cloud

Page 44: I Love APIs - Oct 2015

Human

Client Devices

Cloud

Page 45: I Love APIs - Oct 2015

Human

Client Devices

Cloud

Page 46: I Love APIs - Oct 2015

Human

Client Devices

Cloud

custom UI code

custom server code

Page 47: I Love APIs - Oct 2015

Every time we write a function, we’re designing an API.

Page 48: I Love APIs - Oct 2015

We're just giving you functions that return functions that you do things with.

Doug WilsonLead Maintainer, Express

Page 49: I Love APIs - Oct 2015

)

}

(function {

Page 50: I Love APIs - Oct 2015

)

}

(function {a b c, ,

Page 51: I Love APIs - Oct 2015

)

}

(function {a b c, ,console.log(“hi”);

Page 52: I Love APIs - Oct 2015

)

}

(function {a b c, ,

console.log(“hi”);

return a b c;+ +

Page 53: I Love APIs - Oct 2015

)

}

(function {a b c, ,

console.log(“hi”);

return a b c;+ +

if (Math.random()>0.5) {

} throw new Error();

Page 54: I Love APIs - Oct 2015

)

}

(function {

console.log(

a

b

c

return a b c;+ +

exits

inputs

throw new Error();

if (Math.random()>0.5) {

}

behavior

Page 55: I Love APIs - Oct 2015

console.log(

a

b

c

exitsinputs

Output: number

Output: Error

error

success

Description: Sorry, you got unlucky.

First number

Second number

Third number

(e.g. 7)

(e.g. 2)

(e.g. 3)

(e.g. 1)

DESCRIPTION: Add the 3 provided numbers together.

MORE INFO URL: http://example.com/docs/math/add

FRIENDLY NAME: Add numbers

PACKAGE: machinepack-math (v3.2.9)

*

*

*

Page 56: I Love APIs - Oct 2015

The Node Machine Project

Page 57: I Love APIs - Oct 2015

Like Swaggerfor

node-machine.org/spec

JavaScript functions.

Page 58: I Love APIs - Oct 2015

Like Swaggerfor

node-machine.org/spec

middleware.

Page 59: I Love APIs - Oct 2015

Like Swaggerfor

node-machine.org/spec

Node modules.

Page 60: I Love APIs - Oct 2015

npm install

Page 61: I Love APIs - Oct 2015

npm publish

Page 62: I Love APIs - Oct 2015

Machinepacks

node-machine.org/spec

Page 63: I Love APIs - Oct 2015
Page 64: I Love APIs - Oct 2015
Page 65: I Love APIs - Oct 2015
Page 66: I Love APIs - Oct 2015

node-machine.org

sailsjs.org

Page 67: I Love APIs - Oct 2015

Questions?

@mikermcneilnode-machine.org

Page 68: I Love APIs - Oct 2015

The Machine Specification

Branching and convergence

Lamda functions as arguments

Type validation and coercion (recursive)

Automatically generated documentation

machine-­‐as-­‐scriptmachine-­‐as-­‐action

(what’s new)