Last active
March 8, 2017 20:55
-
-
Save jlprat/7195f6cfd68ad5ce133e252157a6060c 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 = { | |
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