Created
November 13, 2017 09:24
-
-
Save Svetixbot/72382141a637195dc4b578d1186e7a60 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 unfiltered.netty.cycle.Plan.Intent | |
import unfiltered.netty.{ServerErrorResponse, cycle} | |
import unfiltered.request.{GET, POST, Path} | |
import unfiltered.response.{BadRequest, ResponseString} | |
import unfiltered.Cycle | |
import unfiltered.directives._ | |
import Directives._ | |
object Mom extends cycle.Plan | |
with cycle.SynchronousExecution with ServerErrorResponse { | |
override def intent = cookPlease orElse | |
areYouDoneYet | |
case class Food(value: String, count: Int) | |
val quantity = data.as.Required[Int] named "count" | |
val foodValue = data.as.Required[String] named "food" | |
implicit val wish = for { | |
q <- quantity | |
v <- foodValue | |
} yield Food(v, q) | |
val cookPlease: Cycle.Intent[Any, Any] = Directive.Intent { | |
case POST(Path("/food")) => for { | |
w <- wish | |
} yield ResponseString( | |
s"you asked for: ${w.value} in: ${w.count}" | |
) | |
} | |
val areYouDoneYet: Intent = { | |
case GET(Path("/food")) => ??? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment