/examples/sbt-scala/src/main/scala/HelloWorldMain.scala

https://github.com/cisco/elsy · Scala · 41 lines · 21 code · 5 blank · 15 comment · 0 complexity · 03bf92b74973fa56f80c58b79d8ac7b8 MD5 · raw file

  1. /*
  2. * Copyright 2016 Cisco Systems, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import akka.actor.ActorSystem
  17. import akka.http.scaladsl.Http
  18. import akka.http.scaladsl.marshallers.xml.ScalaXmlSupport._
  19. import akka.http.scaladsl.server.Directives._
  20. import akka.stream.ActorMaterializer
  21. object HelloWorldMain extends App with Service {
  22. implicit val system = ActorSystem("my-system")
  23. implicit val materializer = ActorMaterializer()
  24. println("Hello world starting on http://localhost:8080/hello ...")
  25. Http().bindAndHandle(routes, "0.0.0.0", 8080)
  26. }
  27. trait Service {
  28. val routes =
  29. path("hello") {
  30. get {
  31. complete {
  32. <h1>Say hello to akka-http</h1>
  33. }
  34. }
  35. }
  36. }