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
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)
}