Search code examples
scalaakkaactorspray

How to forward a request to another actor in Spray?


So in Spray, after doing the basic example, I wanted to extend it to do more things. This is my route:

val API_ROUTING_TREE: Route = pathPrefix("api") {

    pathPrefix("content") {

      pathPrefix("rendered" / Segment) {

        pageName => {

          /*Matches /block/{template}/{blockName}*/
          pathPrefix("block" / Segment) {

            templateName => {

              path(Segment) {

                blockName => (get | post) {
                   ??????????WHAT DOES GO HERE???????????????
                }

              }
            }
          }
        }
      }
    } ~
      path("structured") {
        failWith(new RuntimeException("Not Implemented"))
      }
  }

of course this doesn't compile because of the missing part. What I'd like is to just forward the request (or possibly the request encapsulated with the parameters already extracted) to another actor like myActor ! request... That doesn't work. I can't find examples for this or they really don't fit.


Solution

  • You could refer to this wonderful example and look at the code - Akka and Spray You will find that the example shows how you could delegate processing from a route to another actor. If you follow it you should be able to solve the compilation problem that you seem to face with using "?" like I did...