Skip to content

Instantly share code, notes, and snippets.

@bphenriques
Created June 1, 2020 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bphenriques/af6cdff6ad077507d5189a71adee4f68 to your computer and use it in GitHub Desktop.
Save bphenriques/af6cdff6ad077507d5189a71adee4f68 to your computer and use it in GitHub Desktop.
Scala Ammonite Akka Server
// ### Installation
// sbt: brew install sbt@1
// ammonite: brew install ammonite-repl
// ### Dependencies
import $ivy.`com.typesafe.akka::akka-http:10.1.9`
import $ivy.`com.typesafe.akka::akka-stream:2.5.23`
// ### Configuration
val Host = "localhost"
val Port = 8080
// ### Code
import akka.http.scaladsl.model._
import akka.http.scaladsl.server._
import akka.http.scaladsl.server.Directives._
object WebServer extends HttpApp {
val health = path("health") { get { complete(StatusCodes.OK) } }
val call = post { path("hello-there" / Segment) { phoneNumber: String => complete(StatusCodes.OK, s"Hello!") } }
override def routes: Route = concat(health, call)
}
@main
def main() = {
WebServer.startServer(Host, Port)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment