+ All Categories
Home > Internet > Using hapi plugins to version your API (hapiDays 2014)

Using hapi plugins to version your API (hapiDays 2014)

Date post: 12-Jul-2015
Category:
Upload: dave-stevens
View: 849 times
Download: 5 times
Share this document with a friend
24
Dave Stevens - zappos.com @davestevens84 | [email protected] USING HAPI PLUGINS TO VERSION YOUR API
Transcript
Page 1: Using hapi plugins to version your API (hapiDays 2014)

Dave Stevens - zappos.com

@davestevens84 | [email protected]

USING HAPI PLUGINS TO VERSION YOUR API

Page 2: Using hapi plugins to version your API (hapiDays 2014)

Because fame !== true

WHO?

• Started using node in 2010

• First used hapi fall of 2013

• 6pm.com mobile web in production powered by hapi late 2013 (test)

• hapi 8 in prod today (internal analytics API)

Page 3: Using hapi plugins to version your API (hapiDays 2014)

Let's keep this brief

PROJECT SETUPFull details of project organization:

http://bit.ly/orghapi

Page 4: Using hapi plugins to version your API (hapiDays 2014)

MAIN APPLICATION

Page 5: Using hapi plugins to version your API (hapiDays 2014)

INFO PLUGIN

Page 6: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER

Page 7: Using hapi plugins to version your API (hapiDays 2014)

TEST IT OUT$ curl http://localhost:9000/version

{ "name":"exampleAPI", "version":"1"}

Page 8: Using hapi plugins to version your API (hapiDays 2014)

and it'll introduce some breaking changes

HERE COMES VERSION 2

Page 9: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER

Before After

Page 10: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER - V1$ cd version$ mkdir v1$ mv index.js v1/index.js

Page 11: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER - V2$ cd version$ mkdir v2

Page 12: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER - INDEX

Page 13: Using hapi plugins to version your API (hapiDays 2014)

INFO PLUGIN - INDEX

Page 14: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER - INDEX

Page 15: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER - INDEX$ curl http://localhost:9000/version

{ "name":"exampleAPI", "version":"1"}

Page 16: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER - INDEX$ curl http://localhost:9000/v1/version

{ "name":"exampleAPI", "version":"1"}

Page 17: Using hapi plugins to version your API (hapiDays 2014)

VERSION HANDLER - INDEX$ curl http://localhost:9000/v2/version

{ "statusCode":200, "applicationDetail":{ "name":"exampleAPI", "version":"2" }}

Page 18: Using hapi plugins to version your API (hapiDays 2014)

VERSIONING WITH CUSTOM HEADERhttp://bit.ly/troyhuntapi

Page 19: Using hapi plugins to version your API (hapiDays 2014)

VERSIONING WITH CUSTOM HEADERhttp://bit.ly/troyhuntapi

$ curl -H "api-version: 1" http://localhost:9000/version

{ "name":"exampleAPI", "version":"1"}

Page 20: Using hapi plugins to version your API (hapiDays 2014)

VERSIONING WITH CUSTOM HEADERhttp://bit.ly/troyhuntapi

$ curl -H "api-version: 2" http://localhost:9000/version

{ "statusCode":200, "applicationDetail":{ "name":"exampleAPI", "version":"2" }}

Page 21: Using hapi plugins to version your API (hapiDays 2014)

VERSIONING WITH ACCEPT HEADERhttp://bit.ly/troyhuntapi

Page 22: Using hapi plugins to version your API (hapiDays 2014)

VERSIONING WITH ACCEPT HEADERhttp://bit.ly/troyhuntapi

$ curl -H "accept: application/vnd.exampleapi.v1" http://localhost:9000/version

{ "name":"exampleAPI", "version":"1"}

Page 23: Using hapi plugins to version your API (hapiDays 2014)

VERSIONING WITH ACCEPT HEADERhttp://bit.ly/troyhuntapi

$ curl -H "accept: application/vnd.exampleapi.v2" http://localhost:9000/version

{ "statusCode":200, "applicationDetail":{ "name":"exampleAPI", "version":"2" }}

Page 24: Using hapi plugins to version your API (hapiDays 2014)

^ more stuff like this ^

@DAVESTEVENS84

[email protected] !

github.com/shakefon !

github.com/shakefon/hapiday14


Recommended