Skip to content

Support Conditional Step Execution with "when" Expressions #20

@shalev007

Description

@shalev007

Problem:
Right now, every step in a RestBook playbook runs unconditionally. For real-world use cases (like syncing users or skipping optional steps), we need a way to conditionally execute steps based on variable values or previous responses.


✅ What to Implement

  • Add a new when: field to StepConfig
  • Allow a Jinja2 expression to be evaluated at runtime
  • If when: evaluates to false, the step is skipped
  • Log skipped steps clearly (e.g., "Step 2 skipped (when=false)")
  • Skipped steps should not store or mutate variables

🔧 Example Syntax

steps:
  - name: check-user
    request:
      method: GET
      endpoint: /users/{{ user_id }}
    store:
      - var: user_exists
        jq: '.id != null'

  - name: create-user
    when: "{{ not user_exists }}"
    request:
      method: POST
      endpoint: /users
      data:
        id: "{{ user_id }}"
        email: "{{ user_email }}"

💡 Why It Matters

  • Enables idempotent API workflows by skipping redundant operations
  • Reduces unnecessary API calls and avoids unintended side effects
  • Makes playbooks more dynamic, readable, and declarative
  • Helps backend/data engineers build safer integrations with fewer steps
  • Opens the door for richer control flow (like branching logic)

📎 Related Ideas

  • Allow when: at the phase level to skip entire phases conditionally
  • Log skipped steps clearly in both output and summary logs
  • Add support for --show-skipped in CLI to report skipped steps explicitly
  • Future: Add else: or otherwise: clause to support step-level fallback
  • Combine with dry-run mode to preview which steps would run or skip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions