Created
October 27, 2014 18:32
-
-
Save sam/437c90bfdc8674224492 to your computer and use it in GitHub Desktop.
Have a reverse route match multiple Request Methods in Play Framework
This file contains hidden or 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
object MyController extends Controller with StrictLogging { | |
def index = | |
AdminAction.async { implicit request => | |
request.method match { | |
case "GET" => | |
Future.successful(Ok("GET")) | |
case "POST" => | |
def onError(errors: Form[FooCreateDirective]): Future[Result] = { | |
Future.successful(BadRequest("ERROR")) | |
} | |
def onSuccess(directive: FooCreateDirective): Future[Result] = { | |
operation(directive) map { | |
case Success(_) => Redirect(routes.MyController.index()) | |
case Failure(e) => | |
logger.error("MyController.createOnSuccess failed", e) | |
InternalServerError | |
} | |
} | |
fooCreateForm.bindFromRequest().fold(onError, onSuccess) | |
case _ => Future.successful(MethodNotAllowed(request.method)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment