Skip to content

Instantly share code, notes, and snippets.

@sheki
Created May 28, 2012 11:23
Show Gist options
  • Select an option

  • Save sheki/2818639 to your computer and use it in GitHub Desktop.

Select an option

Save sheki/2818639 to your computer and use it in GitHub Desktop.
Finagle HTTP Server
class ShowService extends Service[Request, Response] {
def apply(request: Request) = {
val response = new DefaultHttpResponse(HTTP_1_1, OK)
response.setContent(copiedBuffer("show service world", UTF_8))
Future.value(Response(response))
}
}
class SearchService(val i : Int) extends Service[Request, Response] {
def apply(request: Request) = {
val response = new DefaultHttpResponse(HTTP_1_1, OK)
response.setContent(copiedBuffer("search service world", UTF_8))
Future.value(Response(response))
}
}
val myShowService = new ShowService
def main(args: Array[String]) {
val handleExceptions = new HandleExceptions
val authorize = new Authorize
val respond = new Respond
val routingService =
RoutingService.byPathObject {
case Root / "api1" / Integer(userId) => myShowService
case Root / "api2" / Integer(userId) => new SearchService(userId)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment