Advertisement
trishLEX

Server

Jul 4th, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.99 KB | None | 0 0
  1. import akka.actor.ActorSystem
  2. import akka.http.scaladsl.Http
  3. import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
  4. import akka.http.scaladsl.server.Directives._
  5. import akka.http.scaladsl.server.Route
  6. import akka.stream.ActorMaterializer
  7.  
  8. /**
  9.   * Created by trishLEX on 03.07.2017.
  10.   */
  11.  
  12. object WebServer {
  13.  
  14.   def main(args: Array[String]) {
  15.     implicit val actorSystem = ActorSystem("system")
  16.     implicit val actorMaterializer = ActorMaterializer()
  17.     implicit val executionContext = actorSystem.dispatcher
  18.  
  19.     val requestHandler = actorSystem.actorOf(RequestHandler.props(), "requestHandler")
  20.  
  21.     val route: Route = {
  22.     path("hello") {
  23.       get {
  24.         complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
  25.       } ~
  26.         post {
  27.           entity(as[String]) {
  28.             json => complete(json)
  29.           }
  30.         }
  31.     }
  32.   }
  33.  
  34.       Http().bindAndHandle(route,"localhost",8080)
  35.  
  36.       println("server started at 8080")
  37.   }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement