Skip to content

Instantly share code, notes, and snippets.

@eyalroth
Last active October 17, 2018 14:43
Show Gist options
  • Save eyalroth/ffb0feba8762479a5c9bd80375146884 to your computer and use it in GitHub Desktop.
Save eyalroth/ffb0feba8762479a5c9bd80375146884 to your computer and use it in GitHub Desktop.
akka-http #2257 - Server routes
import akka.http.scaladsl.server.{Directives, Route}
import com.typesafe.scalalogging.StrictLogging
import scala.concurrent.ExecutionContext
class ServerRoutes(metricsActorRef: ActorRef, cardActorRef: ActorRef, helloActorRef: ActorRef)
extends Pagination with Directives with StrictLogging {
/* --- Methods --- */
/* --- Public Methods --- */
// also surrounded by handleExceptions and handleRejections directives which don't seem to do participate in the bug
def routes: Route = {
encodeResponse {
decodeRequest {
extractExecutionContext { ec =>
routes(ec)
}
}
}
}
def routes(implicit ec: ExecutionContext): Route = {
pathPrefix("myserver") {
path("metrics") {
post {
entity(as[MetricMessage]) { metrics =>
onSuccess(Future(metricsActorRef ! metrics)) {
complete(HttpResponse(StatusCodes.Accepted))
}
}
}
} ~
path("card") {
post {
entity(as[ReportCard]) { card: ReportCard =>
onSuccess(Future(cardActorRef ! card)) {
complete(HttpResponse(StatusCodes.Accepted))
}
}
}
} ~
path("hello") {
post {
entity(as[Hello]) { hello =>
onSuccess(Future(helloActorRef ! hello)) {
complete(HttpResponse(StatusCodes.Accepted))
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment