A deck on the practical reasons why Wordnik moved to the Scala programming language. Also covered is the Swagger REST API framework which is available at http://swagger.wordnik.com
2. Agenda Who is Wordnik? Why bother with this Scala thing? What did we get from it? What is Swagger Why it should matter to you
3. Wordnik Tech Overview API based infrastructure Micro service oriented architecture Business by Scala, Java, MongoDB Beauty by Javascript, Ruby 20M API calls daily Powered by Swagger, inside & out 20B+ hot documents in MongoDB
4. Why Bother with Scala? Not just looking for next new thing “I was just getting good at ${language.name}!” Technology selection has consequences .netvs OSS Flash vs. HTML5 Java is… Stable Fast Widely accepted
5. Why Bother with Scala? Look at the scenery One size does NOT fit all Rise of Ruby, Javascript, node.js, etc. Hey, they did lots of things right Focus on making things easy
6. So What is it? JVM-based language Started by Martin Odersky Functional & OO Typesafe Fully compatible with Java IncludesDizzying Syntax
7. Java Pain Points DRY is difficult with Java Interfaces are great Implementation? Many ways to peel the onion! Easy to follow Often explosive LOC!
8. Example Our REST service Back-end returns different object implementations depending on operation
9. Example Many operations produce models with similar attributes Resulting in a mess of classes
13. Example Implementation is duplicated everywhere Annotations are duplicated everywhere Am I lazy to complain? Consistency Matters!
14. Simplified with Scala Objects can have Traits Like java interfaces + ruby mixins Creates “proper” subtypes Compiler built, concrete classes The “Word” trait… The corresponding impl…
15. Simplified with Scala More traits. Reuse these across your codebase! The other Impls:
16. Simplified with Scala Big deal? Just the beginning of the good stuff Scala syntax In Java, strict syntax is enforced In Scala: “it’s OK unless it’s not”
23. Summary of Scala @ Wordnik Lost NONE of our Java codebase Code reuse is up Code consistency is up Flexibility is up LOC is down Readability is…
24. Why Swagger? Integration with REST APIs is troublesome and inconsistent Different vendors have different REST semantics Client libraries vary wildly by vendor, language Documentation for developers is an afterthought Input parameters, allowable values, models, responses are found via trial & error Internally a PITA YOUR API is too hard to develop against!
25. How Does it Work? Your server produces a Resource List All available APIs http://petstore.swagger.wordnik.com/api/resources.json “It’s like a sitemap for your API!”
26. How Does it Work? Each API declares itself Available operations Parameters Type (path, query, body) Allowable values/data types Input/output models Error responses with descriptions
30. Client Library Generation Code generation based on Resource Spec Template-based Framework Consume REST Methods, Models, Parameters Produce client libraries “Know before you go HTTP” Required values, fields are known by the client Only expose what’s allowed! Swagger filtering removes methods/models you don’t have access to
34. Easy to add For Java/Scala via JAX-RS… Add swagger-core.jar Annotate your models per your @Providerclass Annotate your resources
35. Easy to add For node.js via express Require swagger.js Declare your swagger specs, models Could use AST/DSL to do automatically Add your operations, configure and start
36. Easy DIY The Swagger spec is Language Agnostic! ANY swagger-compliant server can… Use the Swagger client lib generator Use the test framework Use the sandbox UI More server support from Wordnik Play, Rails .net, others community developed
37. Where to go Next Try Swagger swagger.wordnik.com See it in action developer.wordnik.com/docs Download the source/samples swagger.wordnik.com/downloads Discuss it groups.google.com/group/wordnik-api #swagger_doc on freenode