Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyServiceActor extends Actor with MyService {
- // the HttpService trait defines only one abstract member, which
- // connects the services environment to the enclosing actor or test
- def actorRefFactory = context
- // this actor only runs our route, but you could add
- // other things here, like request stream processing
- // or timeout handling
- def receive = runRoute(myRoute)
- }
- // this trait defines our service behavior independently from the service actor
- trait MyService extends HttpService {
- val myRoute =
- path("dictionaries" / Segment / "suggestions"){ dictionaryId =>
- get{
- parameters("ngr"){ ngr =>
- complete("response")
- }
- }
- }
- }
- object Boot extends App {
- // we need an ActorSystem to host our application in
- implicit val system = ActorSystem("on-spray-can")
- // create and start our service actor
- val service = system.actorOf(Props[MyServiceActor], "demo-service")
- implicit val timeout = Timeout(5.seconds)
- // start a new HTTP server on port 8080 with our service actor as the handler
- IO(Http) ? Http.Bind(service, interface = "localhost", port = 8080)
- }
Add Comment
Please, Sign In to add comment