Last active
August 29, 2015 14:15
-
-
Save michalkowol/7f580f976d6f70d20a44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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