Rendering and JSON
Learn about different ways to render a response.
We'll cover the following...
There are many ways to render a response.
Groovy text
If you prefer to use a plain old text document with embedded groovy (much like a GString), you can
use the TextTemplateModule
:
import ratpack.groovy.template.TextTemplateModule;
import static ratpack.groovy.Groovy.groovyTemplate;
import static ratpack.groovy.Groovy.ratpack;
ratpack {
bindings {
module TextTemplateModule
}
handlers {
get(":key") {
def key = pathTokens.key
render groovyTemplate("index.html", title: "$key")
}
}
}
Then create a file named index.html
in the src/main/resources/templates
directory with the following content: ...