Created
May 27, 2015 11:27
-
-
Save zergood/18bae0adc2e774c31233 to your computer and use it in GitHub Desktop.
Spray sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment