Skip to content

Instantly share code, notes, and snippets.

@mfirry
Created April 25, 2015 15:19
Show Gist options
  • Save mfirry/68cdbd13ce84bd12aa56 to your computer and use it in GitHub Desktop.
Save mfirry/68cdbd13ce84bd12aa56 to your computer and use it in GitHub Desktop.
package com.example
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.RouteResult.route2HandlerFlow
import com.typesafe.config.ConfigFactory
import akka.stream.ActorFlowMaterializer
import akka.stream.scaladsl._
import scala.concurrent._
object Main extends App {
val config = ConfigFactory.load()
implicit val system = ActorSystem.create()
implicit val executionContext = system.dispatcher
implicit val materializer = ActorFlowMaterializer()
lazy val route =
get {
path("json") {
import spray.json._
import spray.json.DefaultJsonProtocol._
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
complete(JsObject("message" -> JsString("Hello, World!")))
} ~
path("plaintext") {
complete("Hello, World!")
}
}
val serverSource: Source[Http.IncomingConnection, Future[Http.ServerBinding]] =
Http(system).bind(interface = "localhost", port = 8080)
val bindingFuture: Future[Http.ServerBinding] =
serverSource.to(Sink.foreach { connection =>
connection handleWith route
}).run()
}
@mfirry
Copy link
Author

mfirry commented Apr 25, 2015

name := """akka-http-example"""

version := "0.0.1-SNAPSHOT"

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http-core-experimental" % "1.0-RC1",
"com.typesafe.akka" %% "akka-stream-experimental" % "1.0-RC1",
"com.typesafe.akka" % "akka-http-spray-json-experimental_2.11" % "1.0-RC1"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment