Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:11
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 dacr/c90695117036c9f357c5a6e6ec2615d2 to your computer and use it in GitHub Desktop.
Save dacr/c90695117036c9f357c5a6e6ec2615d2 to your computer and use it in GitHub Desktop.
lorem ipsum generator web service / published by https://github.com/dacr/code-examples-manager #befe18d5-583d-45f4-a08a-5a24707dc0df/f34a390d78e5649a597f4385f247e25281967d6c
// summary : lorem ipsum generator web service
// keywords : scala, loremipsum, webserver, akkahttp
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : befe18d5-583d-45f4-a08a-5a24707dc0df
// created-on : 2020-04-05T18:21:33Z
// managed-by : https://github.com/dacr/code-examples-manager
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
import $ivy.`fr.janalyse::lorem-ipsum-server-akkahttp:1.0.11`
import akka.http.scaladsl._
import akka.http.scaladsl.server.Directives._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import loremipsum.server.akkahttp._
object LoremServer {
implicit val system = akka.actor.ActorSystem("MySystem")
implicit val materializer = akka.stream.ActorMaterializer()
implicit val executionContext = system.dispatcher
val routes = ServiceRoutes(ServiceDependencies.defaults).routes
Http()
.newServerAt("0.0.0.0", 8080)
.bind(routes)
.andThen{case _ => println("Ready and listening on 8080")}
def startAndWait:Unit = Await.ready(LoremServer.system.whenTerminated, Duration.Inf)
}
// Mandatory as LoremServer is asynchronous
LoremServer.startAndWait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment