Skip to main content

Templating

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

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

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.

Requesting user input​

Use prompt to request a value when the template is rendered:

Bearer {{ prompt 'Enter your API token' }}

By default, the answer is reused until Kreya closes. Pass 'none' to request input on every call, or 'persistent' to save the answer locally across restarts. An optional third argument specifies the cache key:

{{ prompt 'Enter your API token' 'persistent' 'api-token' }}

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.

Referencing external secrets​

With the Vaults and secrets feature, you can reference secrets stored in external vault providers. Use the secrets object to access secrets by vault name and secret path:

{{ secrets.my_vault.my_password }}

Features that support templating​

  • Authentication
  • Default settings
  • Vaults and secrets
  • Certificate file paths and passwords
  • Proxy settings: endpoint, username, password and bypass list
  • gRPC metadata
  • gRPC requests
  • gRPC endpoint
  • gRPC timeout
  • gRPC server reflection endpoint
  • REST headers
  • REST query parameters
  • REST path parameters
  • REST requests, including URL-encoded form keys and values, multipart text content and file paths
  • REST endpoint
  • REST path
  • REST importers: OpenAPI URLs and file paths
  • GraphQL headers
  • GraphQL query parameters
  • GraphQL path parameters
  • GraphQL requests
  • GraphQL variables
  • GraphQL endpoint
  • GraphQL path
  • GraphQL schema importers: endpoints, paths, headers, query parameters, path parameters and file paths
  • WebSocket headers
  • WebSocket requests
  • WebSocket endpoint
  • WebSocket path