33
Fastest to Mobile With Scalatra + Swagger @fehguy

Fastest to Mobile with Scalatra + Swagger

Embed Size (px)

DESCRIPTION

Presentation by Tony Tam on using the Scalatra micro web framework with native support for Swagger. This gives the fastest possible server-to-mobile integration with Scala

Citation preview

Page 1: Fastest to Mobile with Scalatra + Swagger

Fastest to Mobile!With Scalatra + Swagger!

!@fehguy!

Page 2: Fastest to Mobile with Scalatra + Swagger

Swagger Philosophy!

Page 3: Fastest to Mobile with Scalatra + Swagger

Swagger Philosophy!

Service documentation sucks!!

typically(

Page 4: Fastest to Mobile with Scalatra + Swagger

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!

Page 5: Fastest to Mobile with Scalatra + Swagger

Swagger Philosophy!•  Solved by machine-readable, discoverable

API contract!•  Should speed up, not slow down

development process!•  External services/proxies not required!

Page 6: Fastest to Mobile with Scalatra + Swagger

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!

Page 7: Fastest to Mobile with Scalatra + Swagger

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!

Page 8: Fastest to Mobile with Scalatra + Swagger

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!

Page 9: Fastest to Mobile with Scalatra + Swagger

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!!

Page 10: Fastest to Mobile with Scalatra + Swagger

Swagger + Scalatra!•  Scalatra is a Lightweight, High-

performance Micro web framework!•  Extremely clean DSL!•  First-class swagger support!•  http://www.scalatra.org!

Page 11: Fastest to Mobile with Scalatra + Swagger

Scalatra as a REST API!

Page 12: Fastest to Mobile with Scalatra + Swagger

Scalatra as a REST API!

Content&Type&Nego,a,on&via&

json4s&

Page 13: Fastest to Mobile with Scalatra + Swagger

Scalatra as a REST API!

Content&Type&Nego,a,on&via&

json4s&Simple&Rou,ng&

Page 14: Fastest to Mobile with Scalatra + Swagger

Scalatra as a REST API!

Content&Type&Nego,a,on&via&

json4s&Simple&Rou,ng&

Param&Extrac,on&

Page 15: Fastest to Mobile with Scalatra + Swagger

Scalatra as a REST API!

Page 16: Fastest to Mobile with Scalatra + Swagger

Swagger + Scalatra!•  Without Swagger Support!

•  With Swagger Support!

Page 17: Fastest to Mobile with Scalatra + Swagger

Swagger + Scalatra!•  Auto-

generation of swagger JSON!!

Page 18: Fastest to Mobile with Scalatra + Swagger

Swagger + Scalatra!•  No ugly Java annotations!!

Page 19: Fastest to Mobile with Scalatra + Swagger

Swagger + Scalatra!•  Model descriptions!

Page 20: Fastest to Mobile with Scalatra + Swagger

Swagger + Scalatra!•  Model descriptions!

Type&safety&has&its&

benefits!&

Page 21: Fastest to Mobile with Scalatra + Swagger

Swagger UI for “free”!

Page 22: Fastest to Mobile with Scalatra + Swagger

Swagger UI for “free”!

Your&Boss&can&try&your&

API!&

Page 23: Fastest to Mobile with Scalatra + Swagger

Going Moble!•  If you are good at scala, you probably

suck at Objective C!

Page 24: Fastest to Mobile with Scalatra + Swagger

Swagger + Mustache!•  Typesafe conversion between swagger to

Objective C!

Page 25: Fastest to Mobile with Scalatra + Swagger

Swagger + Mustache!•  Typesafe conversion between swagger to

Objective C!

Templates&you&can&Tweak!&

Page 26: Fastest to Mobile with Scalatra + Swagger

Mustache Templates!

Page 27: Fastest to Mobile with Scalatra + Swagger

Mustache Templates!

Page 28: Fastest to Mobile with Scalatra + Swagger

Sharing Libraries with Love!

Page 29: Fastest to Mobile with Scalatra + Swagger

Other Mobile SDKs!•  Android + Java!

Page 30: Fastest to Mobile with Scalatra + Swagger

Other Mobile SDKs!•  Android + Java!

Page 31: Fastest to Mobile with Scalatra + Swagger

Other Mobile SDKs!•  Javascript!

Page 32: Fastest to Mobile with Scalatra + Swagger

Scalatra + Swagger!•  Simplest DSL for REST APIs in Scala!•  Minimal dependencies!•  Tested at scale!•  Not “hello world”!•  Apache 2.0 everything!

Page 33: Fastest to Mobile with Scalatra + Swagger

https://helloreverb.com/swagger/!!

Questions?!