Last active
December 19, 2017 23:38
-
-
Save sumew/8a8844c5911e990cf5b9224c57bdc861 to your computer and use it in GitHub Desktop.
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
object WebServer { | |
def main(args: Array[String]) { | |
implicit val system = ActorSystem("my-system") | |
implicit val materializer = ActorMaterializer() | |
implicit val executionContext = system.dispatcher | |
var counter = 0 | |
val route = post { counter +=1 | |
complete(s"Counter incremented to $counter") | |
} ~ get { complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, s"counter is $counter")) | |
} | |
val bindingFuture = Http().bindAndHandle(route, "localhost", 9999) | |
println(s"Server online at http://localhost:9999/\nPress RETURN to stop...") | |
StdIn.readLine() | |
bindingFuture.flatMap(_.unbind()).onComplete(_ => system.terminate()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment