Test with
$ sbt run
And then,
$ curl localhost:8080/mars/hi
$ curl localhost:8080/jupiter/hi
Test with
$ sbt run
And then,
$ curl localhost:8080/mars/hi
$ curl localhost:8080/jupiter/hi
scalaVersion := "2.10.0" | |
resolvers += "spray repo" at "http://repo.spray.io" | |
libraryDependencies ++= Seq( | |
"io.spray" % "spray-can" % "1.1-M7", | |
"io.spray" % "spray-routing" % "1.1-M7", | |
"com.typesafe.akka" %% "akka-actor" % "2.1.0" | |
) |
package universe | |
import akka.actor.Actor | |
import spray.routing.HttpServiceActor | |
class Jupiter extends Actor with HttpServiceActor { | |
def receive = runRoute { | |
(get & path("hi")) { complete("Hi from Jupiter!") } | |
} | |
} |
package universe | |
import akka.actor.Props | |
import spray.routing.SimpleRoutingApp | |
object Main extends App with SimpleRoutingApp { | |
lazy val mars = system.actorOf(Props[Mars]) | |
lazy val jupiter = system.actorOf(Props[Jupiter]) | |
startServer(interface = "localhost", port = 8080) { | |
pathPrefix("jupiter") { ctx => jupiter ! ctx } ~ | |
pathPrefix("mars") { ctx => mars ! ctx } | |
} | |
} |
package universe | |
import akka.actor.Actor | |
import spray.routing.HttpServiceActor | |
class Mars extends Actor with HttpServiceActor { | |
def receive = runRoute { | |
(get & path("hi")) { complete("Hi from Mars!") } | |
} | |
} |