Created
August 9, 2016 03:41
-
-
Save Kalimaha/38e26f8004a08942f2662cdb73b6f510 to your computer and use it in GitHub Desktop.
Simple HTTP Server in Scala implemented with http4s
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
| 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