Community contributed extensions

Router Annotations

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:

These annotations have the following attributes:

@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 indicates content that need to be served statically. It has the following attributes:

@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 head

Issue tracking

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