scala import akka.actor.ActorSystem import akka.http.scaladsl.Http import akka.http.scaladsl.model._ import akka.http.scaladsl.server.Directives._ import akka.stream.ActorMaterializer import scala.io.StdIn object SimpleAPI { def main(args: Array[String]) { implicit val system = ActorSystem("simple-api") implicit val materializer = ActorMaterializer() implicit val executionContext = system.dispatcher val route = path("hello") { get { complete(HttpEntity(ContentTypes.`text/plain(UTF-8)`, "Hello, World!")) } } val bindingFuture = Http().bindAndHandle(route, "localhost", 8080) println("Server online at http://localhost:8080/ Press ENTER to stop...") StdIn.readLine() bindingFuture .flatMap(_.unbind()) .onComplete(_ => system.terminate()) } }


上一篇:
下一篇:
切换中文