Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

The router module allows you to embed your routes inside the controller. It provides a set of annotations to declare your routes next to your controller methods.

branch: master
1 comment

v1.3

latest commit 30c1cd7eaf
Leon Radley leon authored November 30, 2012
Octocat-spinner-32 conf v1.3 November 30, 2012
Octocat-spinner-32 documentation Add @Gets, @Puts annotations November 07, 2011
Octocat-spinner-32 src Rename getControlerName to getControllerName November 30, 2012
Octocat-spinner-32 .gitignore version 1.1-gsylvain35 August 12, 2011
Octocat-spinner-32 README.textile Update documentation November 30, 2012
Octocat-spinner-32 build.properties 1.0 April 13, 2011
Octocat-spinner-32 build.xml Changed to head April 15, 2011
Octocat-spinner-32 commands.py Changed to head April 15, 2011
README.textile

Router Annotations

Written by Nicolas Leroux.
Improved by Leon Radley (digiPlant AB)

Supported annotations

The router module allows you to embed your routes inside the controller. It provides a set of annotations to declare your routes next to your controller methods.

The following annotations are supported at method level:

  • @Post
  • @Put
  • @Get
  • @Delete
  • @Head
  • @WS
  • @Any

These annotations have the following attributes:

  • value: the path to access your controller’s method
  • priority (optional): the priority of the route (lower number is higher priority)
  • accept (optional)
  • format (optional)

@Any matches all the above HTTP methods.

Note that the path uses the same format described in HTTP routing

Examples:

@Get("/emails/{<.*>folderNames}/{messageId}")
public static void email(@Bind(separator = "/")String[] folderNames, int messageId) throws Exception {
   ...
}
 @Post("/login")
public static void authenticate(String username, String password) throws Exception {
   ...
}

The following annotations are supported at class level:

  • @ServeStatic
  • @StaticRoutes

@ServeStatic indicates content that need to be served statically. It has the following attributes:

  • value: The path to access the content
  • directory: the directory you want to access inside the Play! application
  • priority (optional): the priority of the route (lower number is higher priority)

@StaticRoutes allows to define multiple @ServeStatic routes.

Examples:

@ServeStatic(value = "/public/", directory = "public")
public class Application extends Controller {
   ...
}
@StaticRoutes({
    @ServeStatic(value = "/public/", directory = "public"),
    @ServeStatic(value = "/images/", directory = "images")
})
public class Application extends Controller {
   ...
}

Be sure to empty the “routes” file to avoid any conflicting routes.

Enable the router module for the application

In the /conf/dependencies.yml file, enable the router module by adding this line:

The router module

play -> router 1.3

Issue tracking

If you wish to report a bug or wish for a new feature, please use the issue tracker

Something went wrong with that request. Please try again.