Skip to content

Instantly share code, notes, and snippets.

@vkostyukov
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkostyukov/10346801 to your computer and use it in GitHub Desktop.
Save vkostyukov/10346801 to your computer and use it in GitHub Desktop.
Another approach for routing reqs to Finagle's services
val routes = User.routes orElse
Order.routes
// would be great having:
// val backend = RoutingService.byMethodAndPathObjct(routes)
val backend = new RoutingService(
new PartialFunction[Request, Service[Request, Response]] {
def apply(req: Request) = routes((req.method, Path(req.path)))
def isDefinedAt(req: Request) = routes.isDefinedAt((req.method), Path(req.path))
}
)
object User {
val routes: PartialFunction[(Method, Path), Service[Request, Response]] = {
case Method.Get -> Root / "user" => GetUser
}
}
// object GetUser extends Service[]
object Order {
val routes: PartialFunction[(Method, Path), Service[Request, Response]] = {
case Method.Post -> Root / "order" => PostOrder
}
}
// object PostOrder extends Service[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment