Kauri Documentation
 PreviousHomeNext 
6.10.3 Variables available in the scriptBook Index6.11 Common parameters

6.10.4 Advanced things

Since the router configuration is Groovy code, you can write any control structures in it as you like. We advise however to keep the routing configuration as close to static data as possible. This will make it easier to understand for users with no or less knowledge about Groovy.

But just for fun and general knowledge, let us look at some examples.

The following example will create 10 restlets attached to 10 different URIs on the router: "/helloworld0", "/helloworld1", ..., "/helloworld9". The loop is executed during the building of the routing structure, thus not during actual routing.

builder.router {
    10.times { i ->
        restletRoute = restlet(uri: "/helloworld" + i,
                               handle: { request, response ->
            response.setEntity("Hello world from inside the router " + i,
                                mediaType.TEXT_PLAIN)
        })
    }
}

The following example shows two things: the currently constructed component is available inside its following {} part as a variable named current, and it shows how to print things to the console. Again, the print is executed only once, during the building of the routing structure.

builder.router {
     print("The current routing component is: ${current}")
}
 PreviousHomeNext 
6.10.3 Variables available in the script6.11 Common parameters