Session Variable Expansion

WebSurge sessions support Session Variables that you can define in your Configuration and then use in your Http Headers or Http Request content.

Embeddable Variables can be:

  • Session Variables
    Variables declared in the Session Configuration. The defined values are either static strings or can contain environment variables.
    {{ <DefinedVariable> }}

  • Directly Referenced Environment Variables
    Variables can also directly reference environment variables.
    {{ %ENVIRONMNET_VARIABLE% }}

Changing Environment Variables

If you change Environment Variables on the command line or in Windows you have to restart WebSurge to see the updated values.

Session Variables

Session Variables are declared as Key Value pairs in the Session Configuration:

Session Configuration Session Variables

Variables that you define look like this:

userId=frankenUser#2
openAi-api-key=%OPENAI_KEY%
merchId: f24d1212221d9ea3

Values are either hard-coded strings or can be an %ENVIRONMENT_VARIABLE%.

Environment Variables

Environment variables can be used in two ways:

  • In a Session Variable (as shown above)
  • Directly in a {{ %ENVIRONMENT_VARIABLE% }} Expression

Embedding Variables

These variables can then be embedded into the Url, Http Headers or Http Request Content and are specified using using {{ }} syntax, that uses either a defined session key, or a directly embedded Environment variable:

Content-Type: application/json
Authorization: Bearer {{ openAi-api-key }}
x-merchant-id: {{ %MERCHANT_ID% }}
x-merchant-id2: {{ merchId }}

Creating Variables

To create variables you can go to the session configuration and enter them into the Session Variables edit box, one line per variable. Variables can be in the following formats:

With @ prefix (mainly to support Visual Studio/Code style formats):

@varname=value
@token=x3dfeaea29jsg
@openAiKey=%OPENAI_KEY%

or without:

varname=value
token=x3dfeaea29jsg
openAikey=%OPENAI_KEY%
Using Environment Variables

You can use Environment variables for variable names by wrapping the variable in %ENV_VAR% sytnax.

Using Variables in Requests

To use the variables in your requests you can embed them into the Url, Headers or Body of any request in the session.

For example in the body content you might have:

{
    name: "{{varname}}"
}

In a header you might replace a token.

Authorization: Bearer {{token}}

Or use Environment variables directly:

Authorization: Bearer {{ %OPENAI_KEY% }}