Last active
August 29, 2015 13:58
-
-
Save vkostyukov/10346801 to your computer and use it in GitHub Desktop.
Another approach for routing reqs to Finagle's services
This file contains hidden or 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 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