Skip to content

Instantly share code, notes, and snippets.

@caniszczyk caniszczyk/gist:8921257
Last active Aug 29, 2015

What would you like to do?
Composing Services via Finagle
val timelineSvc = Thrift.newIface[TimelineService](...) // #1
val tweetSvc = Thrift.newIface[TweetService](...)
val authSvc = Thrift.newIface[AuthService](...)
val authFilter =[Req, AuthReq, Res, Res] { (req, svc) => // #2
authSvc.authenticate(req) flatMap svc(_)
val apiService =[AuthReq, Res] { req =>
timelineSvc(req.userId) flatMap {tl =>
val tweets = tl map tweetSvc.getById(_)
Future.collect(tweets) map tweetsToJson(_) }
} //#3
Http.serve(":80", authFilter andThen apiService) // #4
// #1 Create a client for each service
// #2 Create new Filter to authenticate incoming requests
// #3 Create a service to convert an authenticated timeline request to a json response
// #4 Start a new HTTP server on port 80 using the authenticating filter and our service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.