Last active
October 17, 2018 14:43
-
-
Save eyalroth/ffb0feba8762479a5c9bd80375146884 to your computer and use it in GitHub Desktop.
akka-http #2257 - Server routes
This file contains hidden or 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.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