Mockzilla logo

Workflow Syntax Reference

A Transition is a rule that defines how Mockzilla should react to a request when operating in Workflow Mode. By combining Conditions and Effects, you can build incredibly complex, stateful API prototypes without writing a single line of backend code.

State

Simple key-value store for session data like tokens or flags.

Mini-DB

Collection-based storage for tables of users, orders, or logs.

Input

Direct access to request body, headers, query, and path params.

1. Conditions

Conditions determine whether a transition is triggered. Mockzilla's condition engine is highly resilient and gracefully handles messy real-world data.

PropertyDescription
SelectorA JSON path to the value you want to check (e.g., input.body.id, state.token).
Operatoreq (==), neq (!=), gt (>), lt (<), exists, contains.
ValueThe value to compare against. Supports full interpolation with {"{{ }}"}.

Advanced Condition Edge Cases

  • Robust contains: Works seamlessly across arrays and strings. If state.tags is ["admin", "beta"], a condition checking if it contains "beta" will pass. It safely returns false if the target is null or undefined.
  • Safe Type Coercion (gt/lt): Mockzilla safely coerces string-numbers (like "42") into actual numbers. If the value isn't a number (like "apple"), it safely evaluates to false without crashing.
  • Graceful Missing Paths: If you use the exists operator on a deeply nested path that doesn't exist (e.g., state.missing.user.id), Mockzilla safely returns false rather than throwing an error.

2. Effects

Effects are actions that modify the Scenario State or the Mini-DB when a transition fires. You can stack multiple effects in a single transition.

EffectDescription
state.setSets a key in the session state to a specific value.
db.pushAppends a new record to an array (table) in the Mini-DB.
db.updateModifies existing records in a Mini-DB table that match your criteria.
db.removeDeletes records from a Mini-DB table that match your criteria.

Complex Effect Scenarios: Best Ways to Use

  • Multi-Step State Updates: Effects run in order. If your first effect sets state.count to 10, your second effect can immediately use {"{{state.count + 5}}"} to set another variable to 15.
  • Bulk Database Updates: The db.update effect is powerful. If you specify a match criteria (e.g., role == "admin"), Mockzilla will update all matching rows in the table simultaneously, not just the first one.
  • Auto-Initialization: If you use db.push on a table that doesn't exist, Mockzilla automatically creates it for you on the fly.

3. The Mini-DB (db)

The Mini-DB is a persistent JSON store. Each Scenario has its own isolated database.

Accessing Database Values

You can access your data using standard dot notation or advanced array predicates:

  • Relational Lookup (Literal): {"{{db.users[role=admin].name}}"} (Finds the first user where role is "admin")
  • Relational Lookup (Dynamic): {"{{db.users[id=input.params.id].email}}"} (Finds the user whose ID matches the current URL parameter)

4. Execution Rules & Best Practices

To master Workflow Mode, follow these core patterns: