Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
USING HAPI PLUGINS TO 
VERSION YOUR API 
Dave Stevens - zappos.com 
@davestevens84 | dstevens@zappos.com
WHO? 
Because fame !== true 
• Started using node in 
2010 
• First used hapi fall of 
2013 
• 6pm.com mobile web in 
prod...
PROJECT SETUP 
Let's keep this brief 
Full details of project organization: 
http://bit.ly/orghapi
MAIN APPLICATION
INFO PLUGIN
VERSION HANDLER
TEST IT OUT 
$ curl http://localhost:9000/version 
{ 
"name":"exampleAPI", 
"version":"1" 
}
HERE COMES VERSION 2 
and it'll introduce some breaking changes
VERSION HANDLER 
Before After
VERSION HANDLER - V1 
$ cd version 
$ mkdir v1 
$ mv index.js v1/index.js
VERSION HANDLER - V2 
$ cd version 
$ mkdir v2
VERSION HANDLER - INDEX
INFO PLUGIN - INDEX
VERSION HANDLER - INDEX
VERSION HANDLER - INDEX 
$ curl http://localhost:9000/version 
{ 
"name":"exampleAPI", 
"version":"1" 
}
VERSION HANDLER - INDEX 
$ curl http://localhost:9000/v1/version 
{ 
"name":"exampleAPI", 
"version":"1" 
}
VERSION HANDLER - INDEX 
$ curl http://localhost:9000/v2/version 
{ 
"statusCode":200, 
"applicationDetail":{ 
"name":"exa...
VERSIONING WITH CUSTOM HEADER 
http://bit.ly/troyhuntapi
VERSIONING WITH CUSTOM HEADER 
http://bit.ly/troyhuntapi 
$ curl -H "api-version: 1" 
http://localhost:9000/version 
{ 
"n...
VERSIONING WITH CUSTOM HEADER 
http://bit.ly/troyhuntapi 
$ curl -H "api-version: 2" 
http://localhost:9000/version 
{ 
"s...
VERSIONING WITH ACCEPT HEADER 
http://bit.ly/troyhuntapi
VERSIONING WITH ACCEPT HEADER 
http://bit.ly/troyhuntapi 
$ curl -H "accept: application/vnd.exampleapi.v1" 
http://localh...
VERSIONING WITH ACCEPT HEADER 
http://bit.ly/troyhuntapi 
$ curl -H "accept: application/vnd.exampleapi.v2" 
http://localh...
@DAVESTEVENS84 
^ more stuff like this ^ 
dstevens@zappos.com 
! 
github.com/shakefon 
! 
github.com/shakefon/hapiday14
Upcoming SlideShare
Loading in …5
×

Using hapi plugins to version your API (hapiDays 2014)

2,952 views

Published on

Organizing your web application using hapi's plugin architecture provides a great deal of flexibility and modularization. This talk details how to utilize this flexibility to version your API.

Published in: Internet
  • Be the first to comment

Using hapi plugins to version your API (hapiDays 2014)

  1. 1. USING HAPI PLUGINS TO VERSION YOUR API Dave Stevens - zappos.com @davestevens84 | dstevens@zappos.com
  2. 2. WHO? Because fame !== true • 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)
  3. 3. PROJECT SETUP Let's keep this brief Full details of project organization: http://bit.ly/orghapi
  4. 4. MAIN APPLICATION
  5. 5. INFO PLUGIN
  6. 6. VERSION HANDLER
  7. 7. TEST IT OUT $ curl http://localhost:9000/version { "name":"exampleAPI", "version":"1" }
  8. 8. HERE COMES VERSION 2 and it'll introduce some breaking changes
  9. 9. VERSION HANDLER Before After
  10. 10. VERSION HANDLER - V1 $ cd version $ mkdir v1 $ mv index.js v1/index.js
  11. 11. VERSION HANDLER - V2 $ cd version $ mkdir v2
  12. 12. VERSION HANDLER - INDEX
  13. 13. INFO PLUGIN - INDEX
  14. 14. VERSION HANDLER - INDEX
  15. 15. VERSION HANDLER - INDEX $ curl http://localhost:9000/version { "name":"exampleAPI", "version":"1" }
  16. 16. VERSION HANDLER - INDEX $ curl http://localhost:9000/v1/version { "name":"exampleAPI", "version":"1" }
  17. 17. VERSION HANDLER - INDEX $ curl http://localhost:9000/v2/version { "statusCode":200, "applicationDetail":{ "name":"exampleAPI", "version":"2" } }
  18. 18. VERSIONING WITH CUSTOM HEADER http://bit.ly/troyhuntapi
  19. 19. VERSIONING WITH CUSTOM HEADER http://bit.ly/troyhuntapi $ curl -H "api-version: 1" http://localhost:9000/version { "name":"exampleAPI", "version":"1" }
  20. 20. VERSIONING WITH CUSTOM HEADER http://bit.ly/troyhuntapi $ curl -H "api-version: 2" http://localhost:9000/version { "statusCode":200, "applicationDetail":{ "name":"exampleAPI", "version":"2" } }
  21. 21. VERSIONING WITH ACCEPT HEADER http://bit.ly/troyhuntapi
  22. 22. VERSIONING WITH ACCEPT HEADER http://bit.ly/troyhuntapi $ curl -H "accept: application/vnd.exampleapi.v1" http://localhost:9000/version { "name":"exampleAPI", "version":"1" }
  23. 23. VERSIONING WITH ACCEPT HEADER http://bit.ly/troyhuntapi $ curl -H "accept: application/vnd.exampleapi.v2" http://localhost:9000/version { "statusCode":200, "applicationDetail":{ "name":"exampleAPI", "version":"2" } }
  24. 24. @DAVESTEVENS84 ^ more stuff like this ^ dstevens@zappos.com ! github.com/shakefon ! github.com/shakefon/hapiday14

×