Я не нашел прочного примера или структуры для разделения маршрутов Spray.io на несколько файлов. Я считаю, что существующая структура моих маршрутов станет очень громоздкой, и было бы неплохо отвлечь их на разных "контроллерах" для очень простого API-интерфейса REST.
Документы не слишком помогают: http://spray.io/documentation/spray-routing/key-concepts/directives/#directives
Вот что я до сих пор:
class AccountServiceActor extends Actor with AccountService {
def actorRefFactory = context
def receive = handleTimeouts orElse runRoute(demoRoute)
def handleTimeouts: Receive = {
case Timeout(x: HttpRequest) =>
sender ! HttpResponse(StatusCodes.InternalServerError, "Request timed out.")
}
}
// this trait defines our service behavior independently from the service actor
trait AccountService extends HttpService {
val demoRoute = {
get {
path("") {
respondWithMediaType(`text/html`) { // XML is marshalled to `text/xml` by default, so we simply override here
complete(index)
}
} ~
path("ping") {
complete("PONG!")
} ~
path("timeout") { ctx =>
// we simply let the request drop to provoke a timeout
} ~
path("crash") { ctx =>
throw new RuntimeException("crash boom bang")
} ~
path("fail") {
failWith(new RuntimeException("aaaahhh"))
} ~
path("riaktestsetup") {
Test.setupTestData
complete("SETUP!")
} ~
path("riaktestfetch" / Rest) { id =>
complete(Test.read(id))
}
}
}
}
Спасибо за помощь в этом!