Kauri Documentation
 PreviousHomeNext 
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.

7.6.7.1 template

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

Syntax:

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

7.6.7.2 resource

This creates a representation which returns a static resource.

Syntax:

resource(src: "uri")

7.6.7.3 custom

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

Syntax:

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.

7.6.7.4 json

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

Syntax:

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.

7.6.7.5 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.

Example:

    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.

7.6.7.6 Common syntax

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

Name

Description

statusCode

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.

mediaType

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

 PreviousHomeNext 
7.6.6 Multiple formats for exceptions and errors8 Templates