Created
August 3, 2016 15:10
-
-
Save johanandren/1d16f4cbf717b49284bb39a87bf42ac3 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
| import akka.actor.{Actor, ActorSystem, Props} | |
| import akka.http.scaladsl.Http | |
| import akka.http.scaladsl.marshalling._ | |
| import akka.http.scaladsl.server.Directives._ | |
| import akka.stream.ActorMaterializer | |
| import http.ActorPerRequest.RequestHandler.Handle | |
| import scala.io.StdIn | |
| object ActorPerRequest extends App { | |
| object RequestHandler { | |
| case class Handle(complete: String => Unit) | |
| } | |
| class RequestHandler extends Actor { | |
| def receive = { | |
| case Handle(complete) => | |
| complete("ok") | |
| context.stop(self) | |
| } | |
| } | |
| implicit val system = ActorSystem() | |
| implicit val materializer = ActorMaterializer() | |
| val route = | |
| pathEndOrSingleSlash { | |
| get { | |
| completeWith(implicitly[ToResponseMarshaller[String]]) { f => | |
| system.actorOf(Props[RequestHandler]) ! RequestHandler.Handle(f) | |
| } | |
| } | |
| } | |
| Http().bindAndHandle(route, "localhost", 8080) | |
| println("ENTER to terminate") | |
| StdIn.readLine() | |
| system.terminate() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment