Skip to content

Instantly share code, notes, and snippets.

@caniszczyk
Last active August 29, 2015 13:56

Revisions

  1. caniszczyk revised this gist Feb 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ val apiService = Service.mk[AuthReq, Res] { req =>
    Future.collect(tweets) map tweetsToJson(_) }
    }
    } //#3
    Http.serve(:80, authFilter andThen apiService) // #4
    Http.serve(":80", authFilter andThen apiService) // #4

    // #1 Create a client for each service
    // #2 Create new Filter to authenticate incoming requests
  2. caniszczyk created this gist Feb 10, 2014.
    20 changes: 20 additions & 0 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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