After have used Play! Framework for a while, I'm taking a first look to Spray. I started from a sample I found on GitHub, now I want to modify it but it's not easy for me to get how it works.
How can I wait for a message from an Actor in the code below?
package api
import akka.actor.ActorRef
import scala.concurrent.ExecutionContext
import spray.routing.Directives
import core.ClassifierActor
class ClassifierService(classifier: ActorRef)(implicit executionContext: ExecutionContext)
extends Directives with DefaultJsonFormats {
import ClassifierActor._
implicit val classifyMessageFormat = jsonFormat4(ClassifyMessage)
val route =
path("classify") {
post {
handleWith {
// The ClassifierActor gets a ClassifyMessage and
// sends a ClassifiedMessage back to the sender.
// How can wait for the ClassifiedMessage here
// and send a HttpResponse back?
cm: ClassifyMessage => classifier ! cm
// ???
}
}
}
}