Last active
August 29, 2015 13:56
-
-
Save caniszczyk/8921257 to your computer and use it in GitHub Desktop.
Composing Services via Finagle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val timelineSvc = Thrift.newIface[TimelineService](...) // #1 | |
val tweetSvc = Thrift.newIface[TweetService](...) | |
val authSvc = Thrift.newIface[AuthService](...) | |
val authFilter = Filter.mk[Req, AuthReq, Res, Res] { (req, svc) => // #2 | |
authSvc.authenticate(req) flatMap svc(_) | |
} | |
val apiService = Service.mk[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