Skip to content

Instantly share code, notes, and snippets.

@michalkowol
Last active August 29, 2015 14:15
Show Gist options
  • Save michalkowol/7f580f976d6f70d20a44 to your computer and use it in GitHub Desktop.
Save michalkowol/7f580f976d6f70d20a44 to your computer and use it in GitHub Desktop.
import akka.actor.{ActorSystem, Props}
import akka.io.IO
import spray.can.Http
import spray.routing._
object Boot {
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem("foo")
val api = system.actorOf(Props[Api], "api")
IO(Http) ! Http.Bind(api, "0.0.0.0", port = 8080)
}
}
class Api extends HttpServiceActor with FooRoute {
def receive: Receive = runRoute {
pathPrefix("api") {
foo
}
}
}
trait FooRoute extends HttpService {
val foo: Route = get {
// http://localhost:8080/api/foo/michal
path("foo" / Segment) { name =>
complete {
s"foo $name"
}
} ~ {
// http://localhost:8080/api/bar
path("bar") {
complete {
"bar"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment