Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val route =
- pathSingleSlash {
- complete("root")
- } ~
- pathPrefix("digit") {
- pathEndOrSingleSlash {
- complete("here a digit")
- } ~
- path(IntNumber) { int =>
- complete(if (int % 2 == 0) "even digit" else "odd digit")
- }
- }
- вот так было в метакомерсе
- val photos: Route = pathPrefix("photos") {
- path("get") {
- (get & parameters("sessionId") & extractExecutionContext) { (sessionId, ec) =>
- implicit val _ec = ec
- extractAuthContext { auth =>
- log(auth, None) {
- val filter = PhotoFilter(sessionIds = List(sessionId))
- onSuccess(LoadPhotosStream(filter).runWith(Sink.seq[Photo]).map(_.toList)) {
- case Nil => complete(404 -> ApiResponse(404, message = Some("session not found")))
- case result => complete(result)
- }
- }
- }
- } ~
- (post & extractExecutionContext & extractStrictEntity(10.seconds)) { (ec, entity) =>
- implicit val _ec = ec
- extractAuthContext { auth =>
- log(auth, None) {
- val f = for {
- req <- entity.convertTo[PhotosRequest]
- result <- LoadPhotosStream(PhotoFilter(ids = req.ids)).runWith(Sink.seq[Photo]).map(_.toList)
- } yield result
- onSuccess(f) {
- case Nil => complete(404 -> ApiResponse(404, message = Some("photos not found")))
- case result => complete(result)
- }
- }
- }
- }
- } ~
- path("add") {
- post {
- request[List[Photo], String] { case (auth, rc, ec) =>
- implicit val _ec = ec
- FutureUtil.serialise(rc)(photo => photoStorage ? SavePhoto(photo, refresh = true, Progress.None, auth)).map(_ => "ok")
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement