Play provides a DSL for routers directly in code. This DSL has many uses, including embedding a light weight Play server, providing custom or more advanced routing capabilities to a regular Play application, and mocking REST services for testing.

The DSL is provided by RoutingDsl. Since you will be implementing actions, you may want to import the static methods from Controller, which includes factory methods for creating results, accessing the request, response and session. So typically you will want at least the following imports:

The :to parameter is extracted out and passed as the first parameter to the router. Note that the name you give to parameters in the path pattern is irrelevant, the important thing is that parameters in the path are in the same order as parameters in your lambda. You can have anywhere from 0 to 3 parameters in the path pattern, and other HTTP methods, such as POST, PUT and DELETE are supported.

Like Play’s compiled router, the DSL also supports matching multi path segment parameters, this is done by prefixing the parameter with *:

In the above examples, the type of the parameters in the lambdas is undeclared, which the Java compiler defaults to Object. The routing DSL in this case will pass the parameters as String, however if you define an explicit type on the parameter, the routing DSL will attempt to bind the parameter to that type: