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.
Upcoming SlideShare
Microservices Tutorial Session at JavaOne 2016
Next
Download to read offline and view in fullscreen.

13

Share

Download to read offline

Build Enterprise APIs WIth Ease (And Scala)

Download to read offline

How to build enterprise REST API's with ease, with examples and source in Scala. From the September 9th, 2014 talk for the Scala Bay meetup group at Netflix in Los Gatos, CA

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Build Enterprise APIs WIth Ease (And Scala)

  1. 1. Welcome Scala Bay
  2. 2. Building Enterprise APIS With 13388
  3. 3. Jason Swartz 3 @swartzrock Q swartzrock Q jswartz@netflix. com
  4. 4. '1 'O'RE| LLY‘ aming Scaia (non FUNCTIONAL PROGRAMMING THEJVM ; - g
  5. 5. NETFLIX
  6. 6. wuunlmumtp JueHotK| |h- 1-uwonu~ nvm- DVDQueoe | °e"e~nrn6“ . . Tffe 1.7 (N Go behind the scenes Mlh 1119 ‘Orange I! 1119 New Bhd(' (251 as they reveal their fevome wanes. Here, Teyior Schlmg talks about playing Piper. 4' , ._, L: Recently Watched Popular on Netflix ‘ mum ORAP 1,’. :'w. .:3:'-1 B -'1 . - I r . .. . _ iiiii . ii/13*
  7. 7. so. .. 1:’ TDSHIHA )1_tl) 3". » ‘A 2 . ,, ‘S . Q Er; -._. (:. ‘r) '_ d A ‘l‘ V. ’ tr». --— . .a vain , .. vu'. >«IuA vmtws Q | ;'3m. ... .c. ... . / .'_ Hoie{ . ... avnmu E Dtlnk __J_ P-an--c rt-. ..m. « u. DIIION / J): OFUNAI wanna . Vlnul -W30)’ ORION MYACMI ONKYD nsamsut
  8. 8. till 3-. = -. is -_ aut_at“-mane 11 (E Netflix Test Studio Use NTS to sell test your device bclorc submitting it for Certification. ‘go 3 EDS Manage all ofyour Electronic Data Services lEDS> here. llllilllfllllil Welcome to Netflix Partner Tools! On this screen you can find links to popular services provided by the Netflix Partner Tools group You can also find news and announcements about future releases. new Drojccts, and updates. Netflix Partner .3ortal Track your project status in Partner Portal and work on operational tasks. Device Admin Administrator Tools um, . r. ... .- » . : ‘Nantio learn tnoti-7V/ e 4:-v: tt. tns Partner Accom-1tManag Sci! service management of your - group. Add. cdit, or rcmovctcam access to Nctllixlools. Testplan Manager Manage your test. plans. addrrcmo cases. and change your harnc
  9. 9. SSO API Server ~<IIIIh . .____, [ml
  10. 10. A” are sso Server -i— Legacy . t
  11. 11. build quickly
  12. 12. fail faster
  13. 13. deploy automatically
  14. 14. enterprise apis with 8380
  15. 15. Layers Deployment
  16. 16. I-
  17. 17. The Right Framework Easy to learn
  18. 18. The Right Framework Easy to learn Easy to develop with
  19. 19. The Right Framework Easy to learn Easy to develop with Integrated
  20. 20. The Right Framework Easy to learn Easy to develop with Integrated Deployable
  21. 21. The Right Framework Easy to learn Easy to develop with Integrated Deployable Fast (enough)
  22. 22. if . -e_——= 7 3 ft ' 'lc ’ 2.. .. . ' ‘K J‘ I . " ss- "“’—: r.. s—-—a__—. —~--"" ‘I ’ Ea” “ . .1’ ml
  23. 23. I 7 . §i . $1 1) I «J :4’ J- / /ade. .. fl 41 fr I ). "*f«. ‘ 4
  24. 24. import org. scalatra. _ class Loginservice extends Scalatraservlet { post ( II/ II) { Created(””) } }
  25. 25. Created?
  26. 26. dyuutgd import org. sca1atra. _ object Created { def applylbody: Any = Unit, headers: Map[String, String]) = { ActionResu1t(ResponseStatus(201,""). body, Map())
  27. 27. .an, huthaufi¢uEnuJirmhnflur class Loginservice extends Scalatraservlet { post(”/ ”) { val token = LoginManager. login(params("user”), params("password”)) token match{ case None = > Unauthorized("Login failed") case Somelt) = > Ok(t) } } }
  28. 28. What About Missing Parameters?
  29. 29. .nhvmYdflhh‘¢uhtIerrrr‘1uche class Loginservice extends Scalatraservlet { post(u/ H) { if (params. get(”user”). isEmpty) { BadRequest(”Param not found: 'user'") } else if (params. get(”password”). isEmpty) { BadRequest(”Param not found: 'password'") } else { } . .. 1
  30. 30. Respect The Codes
  31. 31. ' Dana ti) 1 Follow ' DanaDanger HTTP response codes for dummies. 50x: we fr. '- ed up. 40x: you f. -. .ed up. 30x: ask that dude over there. 20x: cool. cs RepI{. - t3 Ret| .w_>et i Favortted Myra I ll 3 I I I I If 315 PM « 23 Mar 201.?
  32. 32. ' Dana O »; Follow ' Danaoanger HTTP response codes for dummies. 40x: you f. -. .ed up. 20x: oooL cs RepI{. - t3 Pmweet i Favorftsd More Illa IIIBI II? 315 PM — 23 Mar 2012
  33. 33. Act Wisely
  34. 34. HTTP Actions GET
  35. 35. HTTP Actions GET Read
  36. 36. HTTP Actions GET Read PUT
  37. 37. HTTP Actions GET Read PUT Update
  38. 38. HTTP Actions GET Read PUT Update POST
  39. 39. HTTP Actions GET Read PUT Update POST Create
  40. 40. HTTP Actions GET Read PUT Update POST Create DELETE
  41. 41. HTTP Actions GET Read PUT Update POST Create DELETE uh huh
  42. 42. Follow The Path
  43. 43. REST Endpoints / models/ /models/ search / models/ <id> / models/ <id>/ approve / models/ <id>/ publish
  44. 44. %. e / /2. / / /7// /U . .., , o,. ,, /
  45. 45. let The Standards Do The Heavy Lifting
  46. 46. Service l Manager
  47. 47. Service
  48. 48. YEAH, out, too arrow. yIrrmr's JUST ‘Egg e: s‘=3 gee fig sits’: . , . .. ;.; g,rEt-. .e I p I I , , .4 . - 3 '/ ,v "Iii '. *t"'r , :’é3iui3.t§I, tIl: ,E, I?t'; t;l; }lI; RI rrrnmr, ,. s:. t:; I / g l }', '.f'~, ;" ‘ rryhtflil J3 -4‘-I . “ ‘s “. l 21* vr;5;L’fiJ: ’1fi'.9;= u-* or
  49. 49. Fail Fast
  50. 50. Assure Your Before Your Users Do
  51. 51. What Can You Test? DAO
  52. 52. What Can You Test? DAO Managers
  53. 53. What Can You Test? DAO Managers Managers -> DAO
  54. 54. What Can You Test? DAO Managers Managers -> DAO Services
  55. 55. What Can You Test? DAO Managers Managers -> DAO Services Services -> Managers
  56. 56. What Can You Test? DAO Managers Managers -> DAO Services Services -> Managers Browser -> Services
  57. 57. What Can You Test? DAO Managers Managers -> DAO Services Services -> Managers Browser -> Services Services -> Browser
  58. 58. Browser/ Service Testing Jscruoial
  59. 59. I'; l;t E‘ _. 'i I, Jl~‘: ~’: -,. };r. ,*'. ‘_iI | .,| _I " Ill ‘ctr: -cg I, i_‘I_lf—I: : class Loginservicespec extends Scalatrasuite with FlatSpec { addServlet(new Loginservice, "/ *”) ”Login service” should "authenticate users" in { post("/ user= jason&password=1234”) { status should equal(2@0) body. size should be > 10 } } }
  60. 60. .. _A1nIltndua¢9q: fiuIf1u9¢ it should "handle missing parameters" in { post("/ ?user= name”) { status should equal(400) } post(”/ ?password= pass") { status should equal(400) } post("/ ?user= name&password= pass") { status should not equal(40@) } }
  61. 61. let The Test Tools Do The Heavy Lifting
  62. 62. Deployment
  63. 63. Build Script-Ready Deployables
  64. 64. source —e- . war —te . deb —eJ . ami SBT Gradle Aminator
  65. 65. P333 All Tests Before Deploying
  66. 66. : : ;.. .:-JorJkev Ase. L4! or asqardprod . Jttttd Jr . " Home App AMI mm-. ‘T. tux - ' EC} App (at on D», =:. -:IJ5. ll"l uS~---. ‘.>t»1 (VJJ-g “J a) 7 mm Apgoutlan Clnlx her: to configure Alaru mm ‘VV"t‘I' 9 . ,r :4 I21 J. .JJJ. Deme Ann hr. “ )0?! J -r. »mJ. J—, . '.‘z 9 ‘Ex » . .,, ll‘ r; ., J, cloudwmnkny . :| uuL1muru| u<. yJ' cloudrnonkev _(loud'ncnkI: y 20110506143117 ' Run-nno Instance Lint 2 lrnnqu pm to I Ana Juuon Sezur-Ky Acres: was so;
  67. 67. ‘l“I'-. J-s a_rlI= -t, -it-. i~J; rai1r‘. ;iu-Jr»: i?. '.',2 / LSGL; : It1J’JIJJIu In J , " '1-3-II: ' app L AN] '1, L1u. u.~r '. no >‘-' Mid >35 ' was >42: nu: D huh Ar rf=1eI1.J«= rn. aJA. Jto ‘; r.= . 1.1 (1J'r; Jm~: ‘ obrwan-V063 " obrwana/ O64 J ' ~ J I J "jam. . ~. -. . -_, J —. . ' : limits " 1? —— . _,‘. ,.. ,. 1 J1fl| J‘ ll tmulc W ‘ -. .M: :'1.u. »‘. :=. n V JJ. J t . a:. : x4-. ¢:. ~. "V mun: ;. Dulhlv '—| "rl| l _ n J 4' . . gm. .. -1-cu‘ AMI. ‘ " ' 5 ' " ' c"“"‘ 5”” J-Jr . .. 9;-JJ-4.-J: ;JJ—. J» . Caurll '. l.| t~ r. ... m no on , _ . , . __4J'*. 'l3 J: J;; i’Jii_r vgu . 4_. ,, , "‘; 'I' Vi” "-ll: ' ' L Cvcalemul LJou_-Jpn-war. woes Ilnu. 1n-‘l om hr!
  68. 68. cooncoonIoeoooooonooonenooacoaoauooocooootn~aoa¢n~¢fwXt##. M Acocoaonoocotouoenocuouaooeonnouossonnnounuoonouuobduf : £ IIDIIOI nveoavonpa. u§cvnpoo¢: naJww»vn . o o no. at c loQO¢iO¢O0O onooooouooacg ya . r. annooooooonusoouoouoousoqoonooavoootoonv-u-utovotaooiomo uoonooooucococo-vnooouo-nu. ..--on-poo. .u«a. o«unoumov. §uw H o ooIcvOlIoiIlO¢udtr0#n¢J _oo unoonuooocoocuoeueouvoaotaeaz I000tooCootA00000000onnoooooalovoeoonvooooocaveoopmhnéwaflfl Zooooousnoo DtonohtttiooiihlcntlllvnIntuoonillalltti r-raw» aoouvsuoo cannon-o -uco c-cyan-nIJmsea: no uooobooi on-oooou-ooconooo 000000040000vtolaoovnnoodwwfismfi -ococooouoooooooonuccuuoooooauooucoconouuao-nnunusooor—sse;9e ooooooooooo oonuonlva-u-Cudcwowuxu con ovnoovtoacouowbw ooovvuouloovouvoo ocouoanvn-vo-convoys-I 01:00:I| IoooOelIOOOoo| ooo10000005no0n0ooOIooo0vOon~Io4n¢»oCwA ottooovuouoto-ecu ooqooovew noouoouo-«accounts conIoooonooooooInIIonoooooaoocnooooo-altos«I909.-oooqaoahnnud ooo-oooacoaooon-coco-coon. ono-soot-ononu-cannon: -unooonsomg Zoooooa one «cocoons use-concoct: no u usages. to-convex oooooooaooo vocucocooouoaovaoanuoe 9sosococoon. ocanIontocan-noose: ocooooooooasos-ooooonnoooonoac coco-canonwoooooooocooeooooooovo-oouuooouoocoocouooovoooocceu cocoon. -vi-tuna nuuetnoooonoon-0 oouonoaooonvnnnov cnooncoonat-nunooonooocoooooucoooonaooooou-one-otunccov-tuna coconoocoocoooovoooooo-ocnconcnooan ononooncoon-nonouoweocacaoooooooaooooooooucoonoo-aoaooocoanne noooooo-anoncocoon-ooounocoooo ncoooonooooo c. -canoe sense 1 ooooooaaooo-raccoon. Jonnuocooooooocucav ooooooocnc-o uoooooooooooooootoov» OOOOIUIOIIOOOIOI Juoonovouu 001000 on avoowoocco Olllbtci OOUCOOOOOOIOOIQIOIOO. :lOIOIOCCIlCOoI cocoa. .. oououauoocoou coco-ikoo-oooouuocua. cocoons Uta coco-coo-I -. .ovo oonnococr COCO coauoflloeocutoconoo BQIQQO onoouoo. ooo coon . -wuvo vacuum xoe. l0OIoI|0 cacao ooaoccaouooaoo ooofbcocuoocooc nouns: OIOlOCOgIlI o ooee. ..oooooocaooou ucoo-c ocooonaooontoo booonlloooonna-noon . uooo~¢ cv 9 000009 oooooooo-«coco I! IOlII coconu-acetoneoanoI5I. nouooeoonwnooo: .. .. . ... » . ... .. uuI. .. . .. . ... .. ooocuooou caocoo to-coco noon0nonoon-onouoneooooconooooocooooo-one ononoccnno-noosooouocouoooooooooooocooaco oncocuooc-ooouco IOOOIQDIIUIIOOIQQ . ... ... ... ... ... xi 3 owunonooaoooouou ooouooooooonovonail raccoon 9 on 0nOIOIOOJetCD00000¢0009000000IO0I000IOOOCOOCIQIOOIOIIOCIDOOII out-coo uovoocoo account: 0000 out avenue 9 nuuooouuooonoooos at u once CID II -no on 6Inoobbouolthooovttootloul0000000010lvovutonnoooonuooontoonow ounrepo-u-coo9ooo-oo-coocoooaoocoooooaPuoooooaooooooonoooooou not soon a K o osonoooooov-oououoooooooooooo uwooooou ouoooooovocooooouoooo snciloonItoulclttottoooollocou ooooooaoooocoooooaoooono . ououuua-canon: -uoouoooo. oofbooococo-cocoon-aooooo uncut-caoooooooootoo oo. In¢-oovo-ooooc-ooooooo ooooooono auaavuobotovoboo-Iouotou 00.3Ioolnlooauttcooooouuo aoo. at¢uno. ooooogn~o-ac. oofllooooouououoac-ooonooo uo? snoo0ooov9¢~ooouo noo- anal can can u 0 ca an: -uaouuooooooooooouooouoo uuInuocouocoooaoaoooooou uoooouoouaooucouonuoosacvuovlnaao o? o.ooo-noose-oneovoonoo. anon-noon: -uouoouoou 0-soot IlOICC‘”OOI noon: -vnccnooacu-on o nuvvoouoououvuovobooooooloiouotootooootnooooooonouuotooosooao belbtcvotouovovooolcaoIcu0405090000uoloceleectotooaoouoooaooo staccato-u OIOOQsIIIii mootonshun»: nocan«coon: autopsy-nvouauaouoouooon uouctooolvth
  69. 69. Let The Tools Do The Heavy Lifting
  70. 70. _I l Jf_JJ Jjfj; 3,
  71. 71. APIs They See All APIS
  72. 72. 90% of API Usage Is Just Showing Up
  73. 73. l J) swagger huv I. /oelstoreswagger wordnukxorrIaouJ’. xn-—docs EIPU‘ Swagger Sample App Thus IS a sample server Pezstore server. You can find out more about Swagger at hug Juswa e' wo! ;J: J,k. :,<, >rv~ or on Jrc. lreenooe. net. vrswagger. lor this sample, you can use the an: key "spe(JaI—key“ to test the authonzaoon ters Terms of serwce lpetllpetldl : Jm car by ED / peU(petId) usury .1 pm / petl(petId} J J an / pet/ lpelldl Jucalec a net ’I we .3L‘9 vJJm ma / pet/ uploadlmage JDIKl. ILl‘»1“I'l. VgP / pet mu 3 new out to we sir, w / pet / petJfindByStatus ~ no» vex; ‘JV -«axes / pet/ lTndByTags '» "ds news By uags / user/ (username) pet E E E E E E E E HSEI’ E "". l“P'TlP"lal 0" r‘J'. ?‘. rm can only be dove by the Icgged m use- 7VaJ'7"(‘Z€’S -, J.JJ~J J. ,J [J; ,. . j‘J_l J J . :‘JJ]'rI. LL‘ usernane name that need to he string deleted body updmn user object Mode, usur Ja(J . apmnan. llr5lNarr1E( ‘ . Gplra/ Va/ ,. u5nrn. 'irnc(' . cprrorJah Ia5IName[ 'J J J oprromiv) Pararnelevwnlenllype. Jun-(mrJon‘; son . ,, ,m, [. i W, ,0,, a,_V passwordl . .au. JmJ7 nonu ' J oprronafl
  74. 74. ¢Ruhcu1hIEr1fi1PJ§: crH1uJa1H: HficuJ class Loginservice extends Scalatraservlet { post("/ ", operation(postLogin)) { . .. } def postLogin = api0peration[String](”login”, "Authenticate a user and return their token”) . parameters( queryParam[String]("user") . description(”The user name”), queryParam[String]("password") . description(”Their password”)
  75. 75. ShowlH: de LstOperations Expand Operations Raw Login : . ..: /RESTIv1/login/ Response Class Model Tokenkesponse { token (stung) Response Content Type application/ Json Parameters ‘ Parameter Vame De-stnptron Parameter Type Data Type user The user name query string password Their password query string 1 Try it out‘ L . Mode| Cert I ' . _ ‘ ‘ ' Show/ Hxde Listoperations Expand Operatnons Raw Getall mode? (erI'tupVeS. '.rIZ| W1 me speaufied mode! group, sovted by N? DPVers<on Mme en / REST/ v1/mode| Cer1s/ mode| Groups/ (id} ShowlH4de ListOperatit)ns Expand Operatrons Raw Mode| Group :
  76. 76. Let The Doc Utils Do The Heavy Lifting
  77. 77. Layers Deployment
  78. 78. Let Tools Do The Heavy Lifting
  79. 79. So You DUI“: Have To
  80. 80. Now G0 And Write AP| 's With Ease!
  81. 81. Jason Swartz 3 @swartzrock O swartzrock Q jswartz@netflix. com
  82. 82. lll-2JJJlg.3 Fwy N ” Ull al
  • YangXiao7

    Jul. 19, 2016
  • hiroakikobayashi566

    Dec. 22, 2014
  • toshiyukiihara3958

    Dec. 6, 2014
  • TakashiObara

    Dec. 3, 2014
  • ryuichiokada

    Dec. 2, 2014
  • hizuheka

    Dec. 2, 2014
  • AquaMac

    Dec. 2, 2014
  • ysuzuki0327

    Dec. 2, 2014
  • shimabukuro

    Dec. 2, 2014
  • muhaha03

    Dec. 1, 2014
  • daisukehayashi353

    Dec. 1, 2014
  • daiksy

    Dec. 1, 2014
  • yth1

    Oct. 17, 2014

How to build enterprise REST API's with ease, with examples and source in Scala. From the September 9th, 2014 talk for the Scala Bay meetup group at Netflix in Los Gatos, CA

Views

Total views

6,699

On Slideshare

0

From embeds

0

Number of embeds

4,146

Actions

Downloads

20

Shares

0

Comments

0

Likes

13

×