Transformations

Inja Templates give you a powerful way to process JSON formatted data. For example, if you had a message body that contained the JSON { "name": "world" } then the Inja template Hello {{ name }} would become Hello world. The template variables, e.g., {{ name }}, is used as the key into a JSON object and is replaced with the key’s associated value.

Inja Templates default to using `.` notation for JSON keys, i.e., `address.street` => `{ "address": { "street": "value" } }`. If `advancedTemplates` is `true`, Inja Templates use `/` notation, i.e., `address/street` => `{ "address": { "street": "value" } }`

Gloo adds two additional functions that can be used within templates.

apiVersion: gateway.solo.io/v1
kind: VirtualService
metadata:
  name: 'default'
  namespace: 'gloo-system'
spec:
  virtualHost:
    domains:
    - '*'
    name: 'gloo-system.default'
    routes:
    - matcher:
        prefix: '/'
      routeAction:
        single:
          upstream:
            name: 'jsonplaceholder-80'
            namespace: 'gloo-system'
      routePlugins:
        transformations:
          responseTransformation:
            transformation_template:
              body:
                text: 'extractor ({{ foo }}) header ({{ header("date")}}) json ({{ phone }})'
              extractors:
                foo:
                  header: 'date'
                  regex: '\w*, (.+):(.+):(.+) GMT'
                  subgroup: 2