NLinker

Akka-http sample

Mar 27th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.88 KB | None | 0 0
  1. trait Core  {
  2.   implicit val system: ActorSystem = ActorSystem("Suggestion")
  3.   implicit val materializer: ActorFlowMaterializer = ActorFlowMaterializer()
  4.   implicit val ec: ExecutionContext = system.dispatcher
  5. }
  6.  
  7. object AkkaHttpStarter extends App{
  8.   val http = new VanilaHttp with Core{
  9.     override def config: Config = ConfigFactory.load()
  10.   }
  11.  
  12.   http.start()
  13. }
  14.  
  15. trait AkkaHttp {
  16.   this: Core =>
  17.  
  18.   def config: Config
  19.  
  20.   def start() = {
  21.     val route: Route = {
  22.       path("dictionaries" / Segment / "suggestions"){ dictionaryId =>
  23.         get{
  24.           parameters("ngr"){ ngr =>
  25.               complete("response")
  26.           }
  27.         }
  28.       }
  29.     }
  30.  
  31.     Http().bind(
  32.       interface = config.getString("frontend.interface"),
  33.       port = config.getInt("frontend.port")
  34.     ).to(Sink.foreach { conn =>
  35.       conn.flow.join(route).run()
  36.     }).run()
  37.   }
  38. }
Add Comment
Please, Sign In to add comment