Unfiltered? ● A toolkit for HTTP in Scala ● Really, really modular ● Works with Netty and Jetty ● Built for meetup.com realtime API ● Makes good use of Scala's idioms
● A tool for fetching templates for Scala projects ● g8 skazhy/unfiltered-netty-rx ● All SBT plugins for deployment and IntelliJ are included Bootstrapping with giter8
object MyPlan extends cycle.Plan with cycle.ThreadPool with ServerErrorResponse { def intent = { case GET(Path("/")) => ResponseString("Hello!") case OPTIONS(_) => Created ~> Location("/foo") case _ => NotFound } } unfiltered.netty.Http(1337).handler(MyPlan).run()
Pattern matching ● Decomposing data structures to extract certain fields or validate them ● Really powerful in Scala ● “routing” mechanism in Unfiltered
What happens under the hood? class Method(method: String) { def unapply[T](req: HttpRequest[T]) = if (req.method.equalsIgnoreCase(method)) Some(req) else None } object POST extends Method("POST")
Async made easy case req @ GET(Path("/async")) => val futureOp = asyncOperation futureOp.onSuccess { case result => req.respond(Ok ~> ResponseString(result)) } futureOp.onFailure { case _ => req.respond(InternalServerError) }