Skip to content

Instantly share code, notes, and snippets.

@vkostyukov
Last active August 29, 2015 14:15
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/4515ea68467d6d6d5089 to your computer and use it in GitHub Desktop.
Save vkostyukov/4515ea68467d6d6d5089 to your computer and use it in GitHub Desktop.
Quickstart
name := "finch-quickstart"

version := "0.0.0"

scalaVersion := "2.11.5"

libraryDependencies ++= Seq(
  "com.github.finagle" %% "finch-core" % "0.4.0"
)
import io.finch._
import io.finch.request._
import io.finch.response._
import io.finch.route._
import com.twitter.finagle.Service
import com.twitter.finagle.httpx.Httpx
val title = OptionalParam("title") map { _.getOrElse("") }
def hello(name: String) = new Service[HttpRequest, HttpResponse] {
  def apply(req: HttpRequest) = for {
    t <- title(req)
  } yield Ok(s"Hello, $t $name!")
}
val endpoint = Get / ("hello" | "hi") / string /> hello
Await.ready(Httpx.serve(":8081", endpoint)
curl localhost:8081/hello/Bob?title=Mr.
curl localhost:8081/hi/Alice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment