|
1 | 1 | package de.upb.cs.swt.delphi.webapi |
2 | 2 |
|
3 | | -import akka.actor.ActorSystem |
4 | | -import akka.http.scaladsl.Http |
5 | | -import akka.http.scaladsl.server.Directives._ |
6 | | -import akka.stream.ActorMaterializer |
7 | | - |
8 | | -import scala.io.StdIn |
| 3 | +import akka.http.scaladsl.server.HttpApp |
9 | 4 |
|
10 | 5 | /** |
11 | 6 | * Web server configuration for Delphi web API. |
12 | 7 | */ |
13 | | -object Server { |
14 | | - |
15 | | - def main(args: Array[String]): Unit = { |
16 | | - implicit val system = ActorSystem() |
17 | | - implicit val materializer = ActorMaterializer() |
18 | | - implicit val executionContext = system.dispatcher |
| 8 | +object Server extends HttpApp { |
19 | 9 |
|
20 | | - val route = |
| 10 | + override def routes = |
21 | 11 | path("version") { version } ~ |
22 | 12 | path("features") { features } ~ |
23 | 13 | pathPrefix("search" / Remaining) { query => search(query) } ~ |
24 | 14 | pathPrefix("retrieve" / Remaining) { identifier => retrieve(identifier) } |
25 | 15 |
|
26 | 16 |
|
27 | | - val bindingFuture = Http().bindAndHandle(route, "localhost", 8080) |
28 | | - |
29 | | - println(s"Server online at http://localhost:8080/\nPress RETURN to stop...") |
30 | | - StdIn.readLine() // let it run until user presses return |
31 | | - bindingFuture |
32 | | - .flatMap(_.unbind()) // trigger unbinding from the port |
33 | | - .onComplete(_ => system.terminate()) // and shutdown when done |
34 | | - } |
35 | | - |
36 | 17 | private def version = { |
37 | 18 | get { |
38 | 19 | complete { |
@@ -63,5 +44,11 @@ object Server { |
63 | 44 | } |
64 | 45 | } |
65 | 46 |
|
| 47 | + def main(args: Array[String]): Unit = { |
| 48 | + Server.startServer("0.0.0.0", 8080) |
| 49 | + } |
| 50 | + |
66 | 51 |
|
67 | 52 | } |
| 53 | + |
| 54 | + |
0 commit comments