Question

I've been following this blog post about Spray and Akka as it seems to be a reasonable way to separate out the implementation from the routing in an async service. However, this post being > 6 months old the Spray API seems to have changed and the RoutedHttpService it uses about half way down is nowhere to be found.

I'm fairly new to Scala and very new to Spray, and the Spray docs are at best obtuse, so I've been struggling what to replace that bit of the code with.

A couple of questions then:

  1. Is the approach outlined in this post actually sensible?
  2. If the answer to (1) is yes, then what should RoutedHttpService be replaced with?
  3. If the answer to (1) is no, then is there some other docs of 'the right way' to do Spray?

For easy reference, the bit of code in question is this:

trait Api extends RouteConcatenation {
  this: CoreActors with Core =>

  private implicit val _ = system.dispatcher

  val routes =
    new RegistrationService(registration).route ~
    new MessengerService(messenger).route

  val rootService = system.actorOf(Props(new RoutedHttpService(routes))) // :-(  
}
Was it helpful?

Solution

1) The approach described in this post is really nice but it is already advanced Scala programming. My advice, don't use it if you do not understand it.

2) RoutedHttpService is actually from the Eigengo's activator template not from the Spray API, you can find the source code here.

3) You can also have a look at this project, it gives a nice skeleton with less cake pattern composition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top