Last updated January 12, 2010 20:55, by nicolas_leroux
= Play! Annotation Router =
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.
==<a>Issue tracker</a>==
If you wish to report an issue, please use the [http://kenai.com/jira/browse/PLAY_ROUTER_MODULE issue tracker]
== <a>Supported annotations </a> ==
The following annotations are supported at method level:
* '''@Post'''
* '''@Put'''
* '''@Get'''
* '''@Delete'''
* '''@Head'''
* '''@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.
Examples:
<pre name="java">
@Get("/emails/{<.*>folderNames}/{messageId}")
public static void email(@BindAs("/")String[] folderNames, int messageId) throws Exception {
...
}
</pre>
<pre name="java">
@Post("/login")
public static void authenticate(String username, String password) throws Exception {
...
}
</pre>
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
'''@StaticRoutes''' allows to define multiple '''@ServeStatic''' routes.
Examples:
<pre name="java">
@ServeStatic(value = "/public/", directory = "public")
public class Application extends Controller {
...
}
</pre>
<pre name="java">
@StaticRoutes({
@ServeStatic(value = "/public/", directory = "public"),
@ServeStatic(value = "/images/", directory = "images")
})
public class Application extends Controller {
...
}
</pre>
:'''Be sure to empty the "routes" file to avoid any conflicting routes.'''
== <a>Enable the router module for the application</a> ==
In the ''/conf/application.conf'' file, enable the router module by adding this line:
<pre name="text">
# The router module
module.router=${play.path}/modules/router
</pre>





