Spray.ioルートを複数のファイルに分割するための実例や構造が見つかりませんでした。私のルートの現在の構造は非常に面倒なものになり、非常に単純なREST APIアプリケーションのためにそれらを異なる「コントローラ」に抽象化するとよいでしょう。Spray.ioルートを複数の「コントローラ」に分割できますか?
ドキュメントはあまり助けていないように見えます: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))
}
}
}
}
ありがとう!
そのように見えます。手動でservice1〜service2〜service3を書くのではなく、自動的に組み合わせることができる何らかの暗黙的な記述を作成できるのだろうかと思います。ありがとう! – crockpotveggies
ある種の継承問題が生じるように見えるので、Hmmmは選択を解除しました。 'type引数[com.threetierlogic.AccountServ ice.AccountServiceActor]がメソッド適用の型パラメータの境界に一致しない [T <:akka.actor.Actor]' – crockpotveggies
'caseクラスBase(actorRefFactory:ActorRefFactory) 'HttpResponseをGETリクエストのためのレスポンス(部分)として '/ 'にディスパッチできません。現在のレスポンス状態は 'Completed'ですが、 'Uncompleted'でなければなりません。 – crockpotveggies