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