Created
March 9, 2017 03:37
-
-
Save jmcardon/14f2e7ae7e358a5ee8c36b96c1e9686c 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.http.scaladsl.marshallers.sprayjson.SprayJsonSupport | |
import akka.http.scaladsl.server.{ HttpApp, Route } | |
import spray.json.DefaultJsonProtocol | |
case class SomeFooData(foo: String) | |
object SomeFooDataSupport extends DefaultJsonProtocol with SprayJsonSupport { | |
implicit val PortofolioFormats = jsonFormat1(SomeFooData) | |
} | |
object RouteExample extends HttpApp with App { | |
import SomeFooDataSupport._ | |
def route: Route = path("kappa"){ | |
(post & entity(as[SomeFooData])){ | |
fooData => | |
complete(s"The cookie monster did nothing wrong WOOP! ${fooData.foo.toLowerCase()}") | |
} | |
} | |
pathPrefix("someRoute") { | |
path("hello") { | |
(post & entity(as[SomeFooData])) { | |
fooData => | |
complete(s"hey! ${fooData.foo}") | |
} | |
} ~ path("hi") { | |
(post & entity(as[SomeFooData])) { | |
fooData => | |
complete(s"Ho! ${fooData.foo.toUpperCase()}") | |
} | |
} | |
} | |
startServer("localhost", 8080) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment