akka

Akka HTTP

Introduction#

Akka HTTP is a light-weight HTTP server and client library, using akka-streams under the hood

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)

}

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow