Skip to content

Instantly share code, notes, and snippets.

@natbusa
Created January 5, 2013 09:39
Show Gist options
  • Save natbusa/4460764 to your computer and use it in GitHub Desktop.
Save natbusa/4460764 to your computer and use it in GitHub Desktop.
How to chain action in Play! Framework
import play.api._
import play.api.mvc._
sealed trait ChainedAction[A] extends Action[A]
object ChainedAction {
def apply[A](bodyParser: BodyParser[A])(block: Request[A] => Action[A]): ChainedAction[A] =
new ChainedAction[A] {
def parser = bodyParser
def apply(request: Request[A]) = {
block(request)(request)
}
}
def apply[A](block: Request[AnyContent] => Action[AnyContent]): ChainedAction[AnyContent] = {
apply(BodyParsers.parse.anyContent)(block)
}
def apply (block: => Action[AnyContent]): ChainedAction[AnyContent] = {
apply(BodyParsers.parse.anyContent)(_ => block)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment