O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Action parameters in controllers

Web applications should be able to accept dynamic data as part of their canonical URL. An example of this is GET operations of RESTful API web services. Play makes it easy for developers to implement this.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled.
  2. Edit foo_java/app/controllers/Application.java by adding the following action:
        public static Result echo(String msg) {
          return ok("Echoing " + msg);
        }
  3. Edit foo_java/conf/routes by adding the following line:
        GET    /echo/:msg    controllers.Application.echo(msg)
  4. View your new echo page using a web browser:
    http://localhost:9000/echo/foo
    
  5. You should be able to see the text Echoing foo.

For Scala, we need ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required