Created
January 5, 2013 09:39
-
-
Save natbusa/4460764 to your computer and use it in GitHub Desktop.
How to chain action in Play! Framework
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 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