Skip to content

Instantly share code, notes, and snippets.

@DeaconDesperado
Last active May 10, 2016 01:10
Show Gist options
  • Save DeaconDesperado/12684e14de3769b4e3d6e6336c61276d to your computer and use it in GitHub Desktop.
Save DeaconDesperado/12684e14de3769b4e3d6e6336c61276d to your computer and use it in GitHub Desktop.
Too much cake!
trait Registry {
val ec:ExecutionContext
val userService = new UserServiceImpl(ec)
val fooBarService = new FoobarServiceImpl(userService)
}
class RestActor extends Registry with UserRoutes {
def receive = {
userRoutes ~
otherRoutesFromOtherMixins
}
}
trait AccessDirectives extends Directives {
self: Registry =>
val letMeIn:Directive1[Option[User]] = optionalHeaderValueByName("user_auth").hflatMap {
case Some(id) :: HNil => onSuccess(userService.get(id))
case _ => reject()
}
}
trait UserRoutes extends AccessDirectives with HttpService {
self: Registry =>
val userRoutes = {
path(Segment){ userId =>
onSuccess(userService.get(userId)){ user =>
complete(user)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment