Skip to main content

Templating

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

List of features that support templating:

  • Authentication
  • Default settings
  • Certificates
  • gRPC metadata
  • gRPC requests
  • gRPC endpoint
  • gRPC server reflection endpoint
  • REST headers
  • REST query parameters
  • REST requests
  • REST endpoint
  • REST importers
  • GraphQL headers
  • GraphQL query parameters
  • GraphQL requests
  • GraphQL variables
  • GraphQL endpoint
  • GraphQL schema importers
  • WebSocket headers
  • WebSocket requests
  • WebSocket endpoint

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.

Kreya environment data

The active kreya environment can be accessed by the env Scriban object: {{ env.myProperty }}.

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

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

See Generating fake data for the available categories and for generating numbers, GUIDs and dates with custom formats and ranges.

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 through the vars object:

My variable contains {{ vars.my_variable }}

See the dedicated User variables page for details.

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.