Note that there are some explanatory texts on larger screens.

plurals
  1. POCan Spray.io routes be split into multiple "Controllers"?
    text
    copied!<p>I haven't found a solid example or structure to splitting up Spray.io routes into multiple files. I am finding that the current structure of my routes are going to become very cumbersome, and it would be nice to abstract them into different "Controllers" for a very simple REST API app.</p> <p>Docs don't seem to help too much: <a href="http://spray.io/documentation/spray-routing/key-concepts/directives/#directives">http://spray.io/documentation/spray-routing/key-concepts/directives/#directives</a></p> <p>Here's what I have so far:</p> <pre><code>class AccountServiceActor extends Actor with AccountService { def actorRefFactory = context def receive = handleTimeouts orElse runRoute(demoRoute) def handleTimeouts: Receive = { case Timeout(x: HttpRequest) =&gt; 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 =&gt; // we simply let the request drop to provoke a timeout } ~ path("crash") { ctx =&gt; throw new RuntimeException("crash boom bang") } ~ path("fail") { failWith(new RuntimeException("aaaahhh")) } ~ path("riaktestsetup") { Test.setupTestData complete("SETUP!") } ~ path("riaktestfetch" / Rest) { id =&gt; complete(Test.read(id)) } } } } </code></pre> <p>Thanks for help on this!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload