from spray to akka http - multi layer routes with actors

39 views
Skip to first unread message

James

unread,
Jul 18, 2016, 2:16:45 AM7/18/16
to Akka User List
We have bene  using spray and pretty happy about it. The way we use spray on our production is like this.


------------------------------
trait HttpRootActor extends HttpService with TokenAuthenticator {

  implicit def executionContext = actorRefFactory.dispatcher
  implicit val timeout = ActorDict.timeout

  val httpRootRoute = {

    pathPrefix("t1") {

        user: AppUser =>

          ctx => ActorDict.testService1 ! ctx


    } ~ pathPrefix("t2") {

        user: AppUser =>

          ctx => ActorDict.testService2 ! ctx

    } 
  }
}


class TestService1 extends Actor with HttpTestService1 {

  def actorRefFactory = context

  def receive = runRoute(testService1tRoute)

}

trait HttpTestService1 extends HttpService {

  implicit val timeout = ActorDict.timeout

  implicit def executionContext = actorRefFactory.dispatcher

  val testService1tRoute = {


  post {

    pathEnd  {
          import  UserJsonProtocol._
          import spray.httpx.SprayJsonSupport._
 entity(as[User]) {
     user => {
            complete(Map("status"->"OK").toJson.compactPrint)
          }
 
        } 
      }  
    }
  }
}
-------------------------

We are not quite sure how to do this with new AKKA http since there is no HttpService available any more.

Thank you very much!
James

Akka Team

unread,
Jul 27, 2016, 11:03:02 AM7/27/16
to Akka User List
The HttpService trait in Spray is a pretty thin thing, so if you really like that style you can probably mimic it yourself to get the corresponding setup with Akka HTTP, read up on the Http API of Akka and take a look at the Spray sources and you should be able to figure it out.

The big difference would be that you want to end up with a Route that you Http().bindAndHandle rather than the explicit receive block of HttpService.


--
Johan

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages