Created
June 1, 2020 15:42
-
-
Save bphenriques/af6cdff6ad077507d5189a71adee4f68 to your computer and use it in GitHub Desktop.
Scala Ammonite Akka Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ### 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