Can Spray.io routes be split into multiple “Controllers”?

前端 未结 3 776
-上瘾入骨i
-上瘾入骨i 2020-12-23 17:56

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 v

3条回答
  •  旧巷少年郎
    2020-12-23 18:36

    I tried this way from the above code snippet, basic format and works.

    import akka.actor.ActorSystem
    import akka.actor.Props
    import spray.can.Http
    import akka.io.IO
    import akka.actor.ActorRefFactory
    import spray.routing.HttpService
    import akka.actor.Actor
    
    
    /**
     * API endpoints
     *
     * Individual APIs are created in traits that are mixed here
     */
    
    trait Api extends ApiService
    with UserAccountsService
    {
      val route ={
        apiServiceRouting ~
        accountsServiceRouting
      }
    
    }
    
    trait ApiService extends HttpService{
      val apiServiceRouting={
        get{
          path("ping") {
           get {
            complete {
              

    pong

    } } } } } } trait UserAccountsService extends HttpService{ val accountsServiceRouting={ path("getAdmin") { get { complete {

    AdminUserName

    } } } } } class ApiActor extends Actor with Api { override val actorRefFactory: ActorRefFactory = context def receive = runRoute(this.route) } object MainTest extends App { // we need an ActorSystem to host our application in implicit val system = ActorSystem("UserInformaitonHTTPServer") // the handler actor replies to incoming HttpRequests val handler = system.actorOf(Props[ApiActor], name = "handler") // starting the server IO(Http) ! Http.Bind(handler, interface = "localhost", port = 8080) }

提交回复
热议问题