Kauri Documentation
7.6.6 Multiple formats for exceptions and errorsBook Index8 Templates

7.6.7 Representations

To create an actual representation, a few built-in solutions are available, and a way to refer to your own classes to create the representation. template

This creates a template representation, the most common way of producing an HTML or XML response. This uses Kauri's template engine.


template(src: "uri")

The src parameter specifies the template file location, typically this will be a URI using the module protocol such as module:/templates/foo.xml resource

This creates a representation which returns a static resource.


resource(src: "uri") custom

This allows to use your own code to create the representation.


custom(ofClass: "fully qualified class name")
custom(ofBean: "spring bean name")

You can either specify a class or refer to a bean in the Spring container by name. Either way, the resulting object should implement the interface org.kauriproject.representation.RepresentationFactory. See its javadoc for more information. json

Formats an exception or error as json. This should only be used in the exceptions or errors sections.


jsonStatus(statusCode: 500)

The output produced is of the following kind:

  status: "(HTTP status code)",
  description: "",
  throwable: {
    message: "(exception message)",
    type: "(exception fully qualified class name)",
    stackTrace: [
      {class: "...", method: "...", native: true|false, file: "...", line: number}
    cause: { (nested throwable description) }

The description and throwable will only be present when available. Reusing matched values

In the src attributes of the template and resource representations, you can refer to match values from the when nodes, using URI template syntax.


    select {
        when(name: "{name,all}") {
            template(src: "module:/templates/{name}.xml")

If you have nested select's, you can use "../" syntax to walk up in the select node stack. Common syntax

On each representation-creating node, you can use the following optional parameters.




an integer, specifying the HTTP status code for the response. For normal representations this is by default 200, for exceptions this is by default 500.


the media type for the response. (todo: behavior and defaults depend on representation implementation)

7.6.6 Multiple formats for exceptions and errors8 Templates