0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Akka HTTP のミニマルストローク Hello World

Last updated at Posted at 2016-10-31

はじめに

Akka HTTP を使ってミニマルストローク Hello World をやったときの記録です。
環境は前回の ScalikeJDBC と同じく、以下の通り。

  • JDK 8.0
  • Scala 2.11.8
  • sbt 0.13.12

build.sbt を作る

Maven Repositry で Akka HTTP を検索し sbt 向けの記述をコピペします。
また scalaVersion を端折ったら Scala 2.10 向けにビルドされてしまう(?)ようで
実行時に ClassNotFoundException が発生しますのでご注意を・・

build.sbt
scalaVersion := "2.11.8"

// https://mvnrepository.com/artifact/com.typesafe.akka/akka-http-experimental_2.11
libraryDependencies += "com.typesafe.akka" % "akka-http-experimental_2.11" % "2.4.11"

Hello World

これ以上どこかを削ったら機能しなくなるミニマルな Hello World がこちらです。
プロジェクトフォルダで sbt を実行し、ブラウザで http://localhost:8080/ にアクセスしてみましょう。

HelloAkkaHttp.scala
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._

object HelloAkkaHttp extends App {

  implicit val actorSystem = ActorSystem()
  implicit val actorMaterializer = ActorMaterializer()

  val route =
    pathSingleSlash {
      get {
        complete {
          "Hello World"
        }
      }
    }

  Http().bindAndHandle(route, "localhost", 8080)

}

この後は

このページの例が動いたら、あらためて

等をよく読むのが良いのではないかと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?