Akka HTTP

Other topics

Akka HTTP server: Hello World (Scala DSL)

The following app will start an HTTP server listening on port 8080 that returns Hello world on GET /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)

}

Contributors

Topic Id: 10108

Example Ids: 31018

This site is not affiliated with any of the contributors.