How do I iterate over the routes in a playframework 2 scala application?

playframework-2.0, routes, scala

Solution

You can’t really do that with Play 2.0.

Routes are defined as a `PartialFunction[RequestHeader, Handler]`, there is no way to know the domain of this function.

Nevertheless, as shown in the not found template, you can retrieve some information on the application’s routes: the Play 2.0 router generates a `documentation` field returning, for each route of the application, its HTTP method (`GET`, `PUT`, etc.), its path pattern and finally the call as it was written in the `conf/routes` file.

The router generates a `Routes` object which is loaded by your Play application when started, you can access it as follows:

for {
  routes <- play.api.Play.current.routes.toList
  (method, pattern, call) <- routes.documentation
} yield {
  …
}

Problem

What is the equivalent for play.mvc.Router.routes in playframework 2 scala? In playframework 1.x I could Iterate over the available routes in the controller: ``` for(Route route:Router.routes){ ... } ``` How would I do this with playframework 2 scala? The not found dev mode template seems to be able to iterate over them but I need to do this in a controller.

Original source