Akka HTTP 服务器 Hello World(Scala DSL)
以下应用程序将启动侦听端口 8080 的 HTTP 服务器,该服务器将在 GET /hello/world
上返回 Hello world
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import akka.stream.ActorMaterializer
import scala.concurrent.Await
import scala.concurrent.duration.Duration
object HelloWorld extends App {
implicit val system = ActorSystem("ProxySystem")
implicit val mat = ActorMaterializer()
val route: Route = get {
path("hello" / "world") {
complete("Hello world")
}
}
val bindingFuture = Http().bindAndHandle(Route.handlerFlow(route), "127.0.0.1", port = 8080)
Await.result(system.whenTerminated, Duration.Inf)
}