2. Whoami
Code / train Scala for a living
Lately for a NYC startup
Using Unfiltered
Currently freelancer
Former Xebia
Former TomTom
Former Sun Microstems
Former ...
20. SCAML
In a Nutshell
!!! <!DOCTYPE html PUBLIC "-//…
%html <html>
%body <body>
.masthead <div class="masthead"/>
#main <div id="main"/>
%p(onclick="") YES <p onclick="">YES</p>
:javascript <script language="javascript"/>
:markdown
*Nice* <p><em>Nice</em></p>
</body>
</html>
21. Extractors ①
case … => …
case … & … & … => …
GET(…) Accept(…)
POST(…) UserAgent(…)
DELETE(…) Host(…)
PUT(…) IfModifiedSince(…)
Path(…) Referer(…)
22. Extractors ②
case GET(_)
case GET(Path(path))
case Path(Seg("give","me",something :: Nil))
(Matches "/give/me/money", setting something to "money".)
case Path("/") & Params(params)
case Accept("application/json")
23. Extractors ③
HttpRequest[A] → { case … => … }
object DotJson {
unapply[A](req: HttpRequest[A]) =
req.uri.endsWith(".json")
}
case DotJson() => ResponseString("Json!")
24. QParams ☣
MONAD ALERT
import unfiltered.request.QParams._
case req @ Params(params) =>
val expected = for {
lat <- lookup("lat") is required("missing")
lon <- lookup("lon") is required("missing")
} yield {
Ok ~>
PlainTextContent ~>
ResponseString("%s, %s".format(lat.get, lon.get))
}
expected(params) orFail { failures =>
BadRequest ~> ResponseString(failures.mkString)
25. But wait,
there's more
- OAuth
- Secure switch - Upload
- Routing kit - Netty binding
- Basic authentication - Web Sockets
26. Key takeaways
Simple ☺
Retain control ☺
Used for real apps ☺
Hit the ground running ☺
Encode your own policies ☺
The source code is the documentation ⚇
Typesafe & extensible ☺☺☺
Vibe ☹