KEMBAR78
Fastest to Mobile with Scalatra + Swagger | PDF
Fastest to Mobile!
With Scalatra + Swagger!
!
@fehguy!
Swagger Philosophy!
Swagger Philosophy!
Service documentation sucks!
!
typically(
Swagger Philosophy!
•  Communicating is too much work!
– Users don’t want to write YOUR SDK!
– If you’re good at Ruby, you suck at GO!
•  Consumers need a contract!
– Service logic doesn’t belong in the SDK!
•  Services are plumbing!
– We shouldn’t all be plumbers!
– Business logic is your business!
Swagger Philosophy!
•  Solved by machine-readable, discoverable
API contract!
•  Should speed up, not slow down
development process!
•  External services/proxies not required!
What is Swagger?!
•  An interface to your service!
– Described in JSON!
•  It is a contract to your service!
•  Enables “bigotry-free” restful design with
emphasis on getting things done!
– Many ways to delete a Pet!
How does it work?!
•  Discoverable at runtime, not compile-time!
•  It’s just JSON!
•  No server integration required!
– You can describe an API that’s not even yours!
– Deploy anywhere! Put it on github!!
– Swagger is JUST a way to describe an API!
But Why?!
•  Machine-readable contract!
–  Description of *everything* the server
can do!
–  Server-controlled documentation!
–  Server/language/platform/deployment
agnostic!
•  Documentation, code generation,
client generation!
–  Like Headers for C, Interfaces for Java!
How do you add Swagger?!
•  Static Files!
– Manually crafted JSON!
•  Heuristics!
– Traffic inspection!
•  Code inspection!
– Code comments, static annotations!
•  Runtime generation!
It’s just JSON!!
Swagger + Scalatra!
•  Scalatra is a Lightweight, High-
performance Micro web framework!
•  Extremely clean DSL!
•  First-class swagger support!
•  http://www.scalatra.org!
Scalatra as a REST API!
Scalatra as a REST API!
Content&Type&
Nego,a,on&via&
json4s&
Scalatra as a REST API!
Content&Type&
Nego,a,on&via&
json4s&
Simple&Rou,ng&
Scalatra as a REST API!
Content&Type&
Nego,a,on&via&
json4s&
Simple&Rou,ng&
Param&
Extrac,on&
Scalatra as a REST API!
Swagger + Scalatra!
•  Without Swagger Support!
•  With Swagger Support!
Swagger + Scalatra!
•  Auto-
generation of
swagger JSON!!
Swagger + Scalatra!
•  No ugly Java annotations!!
Swagger + Scalatra!
•  Model descriptions!
Swagger + Scalatra!
•  Model descriptions!
Type&safety&
has&its&
benefits!&
Swagger UI for “free”!
Swagger UI for “free”!
Your&Boss&
can&try&your&
API!&
Going Moble!
•  If you are good at scala, you probably
suck at Objective C!
Swagger + Mustache!
•  Typesafe conversion between swagger to
Objective C!
Swagger + Mustache!
•  Typesafe conversion between swagger to
Objective C!
Templates&
you&can&
Tweak!&
Mustache Templates!
Mustache Templates!
Sharing Libraries with Love!
Other Mobile SDKs!
•  Android + Java!
Other Mobile SDKs!
•  Android + Java!
Other Mobile SDKs!
•  Javascript!
Scalatra + Swagger!
•  Simplest DSL for REST APIs in Scala!
•  Minimal dependencies!
•  Tested at scale!
•  Not “hello world”!
•  Apache 2.0 everything!
https://helloreverb.com/swagger/!
!
Questions?!

Fastest to Mobile with Scalatra + Swagger