Skip to content

Instantly share code, notes, and snippets.

@Svetixbot
Created November 13, 2017 09:24
Show Gist options
  • Save Svetixbot/72382141a637195dc4b578d1186e7a60 to your computer and use it in GitHub Desktop.
Save Svetixbot/72382141a637195dc4b578d1186e7a60 to your computer and use it in GitHub Desktop.
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