Skip to content

Instantly share code, notes, and snippets.

@Kalimaha
Created August 9, 2016 03:41
Show Gist options
  • Select an option

  • Save Kalimaha/38e26f8004a08942f2662cdb73b6f510 to your computer and use it in GitHub Desktop.

Select an option

Save Kalimaha/38e26f8004a08942f2662cdb73b6f510 to your computer and use it in GitHub Desktop.
Simple HTTP Server in Scala implemented with http4s
import org.http4s.server.{Server, ServerApp}
import org.http4s.server.blaze._
import scalaz.concurrent.Task
import org.http4s._, org.http4s.dsl._
import org.http4s.server.syntax._
object Main extends ServerApp {
val helloService = HttpService {
case GET -> Root / "hello" / name =>
Ok(s"Hello, $name.")
}
val goodbyeService = HttpService {
case GET -> Root / "goodbye" / name =>
Ok(s"Goodbye, $name.")
}
val services = helloService orElse goodbyeService
override def server(args: List[String]): Task[Server] = {
BlazeBuilder
.bindHttp(8080, "localhost")
.mountService(services, "/api")
.start
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment