Skip to content

Instantly share code, notes, and snippets.

Created May 20, 2016 08:46
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Basic akka-http server
package io.scalac.conductr.example
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import{Sink, Source}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.language.postfixOps
object Server extends App {
implicit val actorSystem = ActorSystem("microservice-as")
implicit val flowMaterializer = ActorMaterializer()
val httpService = Http()
val HOST = ""
val PORT = 8080
val serverSource: Source[Http.IncomingConnection, Future[Http.ServerBinding]] =
httpService.bind(interface = HOST, PORT)
val binding: Future[Http.ServerBinding] = { connection =>
println("Accepted new connection from {}", connection.remoteAddress)
connection handleWith route
println(s"Server is now online at http://$HOST:$PORT\n")
//shutdown Hook
import actorSystem.dispatcher
scala.sys.addShutdownHook {
.onComplete { _ =>
Await.result(actorSystem.whenTerminated, 60 seconds)
println("Terminated... Bye")
//basic route
def route = complete {
"Welcome to microservice"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment