Variables
Variables let you store key-value pairs that can be referenced in response templates. mockd supports three scopes of variables.
Variable Scopes
Section titled “Variable Scopes”| Scope | Syntax | Lifetime | Limit (Pro) |
|---|---|---|---|
| Global | {{globals.name}} | Persists across all projects | 50 |
| Project | {{project.name}} | Persists across all endpoints in a project | 25 |
| Endpoint | {{endpoint.name}} | Set by store_variable actions at runtime | — |
Global Variables
Section titled “Global Variables”Account-level variables accessible from any project. Useful for shared values like API keys, environment names, or base URLs.
Manage from the dashboard under Account → Variables, or via the API.
Example
Section titled “Example”Set a global variable apiVersion = v2, then use it in any endpoint:
{ "version": "{{globals.apiVersion}}", "data": []}Project Variables
Section titled “Project Variables”Scoped to a single project. Useful for project-specific configuration that multiple endpoints share.
Manage from the project settings page.
Example
Section titled “Example”Set a project variable environment = staging:
{ "env": "{{project.environment}}", "service": "user-api"}Endpoint Variables
Section titled “Endpoint Variables”Runtime variables set by store_variable actions within rules. These persist across requests to the same endpoint and are useful for stateful mocking — like incrementing a counter or remembering the last request.
Example
Section titled “Example”A rule with a store_variable action stores the request body’s userId field:
- Action type: Store Variable
- Name:
lastUser - Value:
{{request.body.userId}}
Subsequent requests can reference it:
{ "lastUser": "{{endpoint.lastUser}}", "currentUser": "{{request.body.userId}}"}Variables vs Template Variables
Section titled “Variables vs Template Variables”Variables (this page) are user-defined and persistent. Template variables like {{$uuid}} and {{$randomName}} are built-in generators that produce fresh values on every request. Both use the same {{ }} syntax and can be combined in a single response body.