Skip to main content

Templating

With the templating feature, you can insert environment values almost everywhere inside Kreya.

info

Starting with Kreya 1.7, directly referencing environment variables (ex. {{ endpoint }}) has been deprecated. Please use the env object to reference environment variables, for example {{ env.endpoint }}.

List of features that support templating:

  • Authentication
  • Default settings
  • Certificates
  • gRPC metadata
  • gRPC requests
  • gRPC endpoint
  • gRPC server reflection endpoint
  • REST headers
  • REST requests
  • REST endpoint
  • REST importers

Templating language

Kreya uses Scriban as its templating language. Usually, only variables are used, such as {{ env.endpoint }}. However, Scriban supports more complex features.

Take a look at the Scriban language guide and built in functions.

Generating fake data

In addition to the default Scriban features, Kreya also implements Bogus to allow fake data generation. For example, using

I am {{ faker.name.full_name }}

will result in a random name:

I am Jazlyn Gorczany

Referencing user variables Pro / Enterprise

User variables can be set via scripting. If you set a user variable via scripting

kreya.variables.set('my_variable', 12345);

it can be referenced via templating:

My variable contains {{ vars.my_variable }}

Referencing authentication configurations

Should you need to send authentication tokens via custom headers, in the request body or elsewhere, simply reference your existing authentication configurations. For example, if you have a basic authentication configuration called "My Auth":

The value of {{ auth.configs.my_auth.name }} is {{ auth.configs.my_auth.value }}

If you also need the "authentication prefix" (Basic, Bearer, ...), use prefixed_value instead of value.