Skip to content

Variables

Variables let you store key-value pairs that can be referenced in response templates. mockd supports three scopes of variables.

ScopeSyntaxLifetimeLimit (Pro)
Global{{globals.name}}Persists across all projects50
Project{{project.name}}Persists across all endpoints in a project25
Endpoint{{endpoint.name}}Set by store_variable actions at runtime

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.

Set a global variable apiVersion = v2, then use it in any endpoint:

{
"version": "{{globals.apiVersion}}",
"data": []
}

Scoped to a single project. Useful for project-specific configuration that multiple endpoints share.

Manage from the project settings page.

Set a project variable environment = staging:

{
"env": "{{project.environment}}",
"service": "user-api"
}

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.

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