Template Variables

Complete reference guide for all template variables available in moclojer. Learn how to access request data and use built-in functions in your responses.

This reference guide provides a complete list of all template variables available in moclojer. Template variables use the {{variable}} syntax and are replaced with actual values when processing requests.

Path Parameters

Extract values from URL path segments defined with :parameter syntax.

Syntax

path: /users/:id/posts/:postId
body: >
  {
    "user_id": "{{path-params.id}}",
    "post_id": "{{path-params.postId}}"
  }

Examples

Single parameter:

path: /users/:id
# Request: GET /users/123
# Result: {{path-params.id}} = "123"

Multiple parameters:

Typed parameters:

Available Types

  • string (default) - Any string value

  • int - Integer numbers only

  • uuid - UUID format validation

  • date - Date format validation

  • boolean - Boolean values (true/false)

Query Parameters

Access URL query string parameters that come after the ? in URLs.

Syntax

Examples

Simple query parameters:

Array parameters:

URL encoded parameters:

JSON Body Parameters

Access data from JSON request bodies in POST, PUT, PATCH requests.

Syntax

Examples

Simple properties:

Nested objects:

Array elements:

Complex nested structures:

Data Type Handling

Strings (require quotes):

Numbers (no quotes needed):

Booleans (no quotes needed):

Header Parameters

Access HTTP request headers using the header name.

Syntax

Examples

Standard headers:

Custom headers:

Case sensitivity:

Built-in Functions

Special template functions that provide dynamic values.

{{now}}

Returns the current timestamp in ISO 8601 format.

{{uuid}}

Generates a random UUID v4.

{{random}}

Generates random numbers (if supported).

WebSocket Template Variables

Special variables available in WebSocket responses.

{{message}}

The complete received message content.

WebSocket Path Parameters

Same as HTTP path parameters.

Advanced Usage

Combining Multiple Parameters

Conditional Content

String Interpolation

Error Handling

Missing Parameters

When a parameter is not present in the request, it appears as an empty string:

Invalid JSON

If JSON body is malformed, json-params will be empty:

Special Characters

Template variables handle URL encoding and JSON escaping automatically:

Best Practices

1. Use Appropriate Data Types

2. Provide Default Values

3. Validate Parameter Types

4. Handle Missing Parameters Gracefully

5. Use Meaningful Parameter Names

Examples by Use Case

User Profile API

Order Creation

This reference covers all available template variables in moclojer. For more advanced templating techniques, see Advanced Templating.

Last updated

Was this helpful?