Skip to main content

Examples & Recipes

This section provides practical examples and proven patterns for common Wolf DSL use cases. Each example is self-contained and can be adapted to your specific needs.

Quick Examples

Hello World Flow

Schema Greeting {
string message
string timestamp
}

value helloWorld -> Greeting {
message: "Hello, Wolf DSL!"
timestamp: ${currentDate("yyyy-MM-dd HH:mm:ss")}
}

Mapping formatGreeting input helloWorld output Greeting {
Greeting.message = " " + helloWorld.message
Greeting.timestamp = helloWorld.timestamp
}

Flow simpleFlow {
Start helloWorld {
transition { formatGreeting }
}
formatGreeting {}
}

Simple REST API Call

Schema ApiResponse {
string status
User data
}

Schema User {
string id
string name
string email
}

Service userService method GET as getUser
input UserId output ApiResponse {
Url -> @Config("api.base.url")
Path -> ${"/users/" + UserId.id}
@Header Accept -> ${"application/json"}
@Header Authorization -> ${"Bearer " + @Config("api.token")}
}

Comprehensive Examples

Use Case Categories

Data Processing

Service Integration

Advanced Patterns

Pattern Library

Common Patterns

1. Service with Fallback

Flow resilientFlow {
Start request {
transition {
@Config("primary.service.enabled") == "true"
? primaryService
: fallbackMapping
}
}
primaryService {
transition { responseTransform }
}
fallbackMapping {
transition { responseTransform }
}
responseTransform {}
}

2. Conditional Data Processing

Mapping processUser input RawUser output ProcessedUser {
ProcessedUser.id = RawUser.id
ProcessedUser.name = upperCase(RawUser.name)
ProcessedUser.email = lowerCase(RawUser.email)
ProcessedUser.status = if RawUser.age >= 18 then "adult" else "minor"
ProcessedUser.permissions = if RawUser.role == "admin"
then ["read", "write", "delete"]
else ["read"]
}

3. Array Processing

Mapping filterAndTransform input UserList output FilteredUsers {
// Filter active users and transform
FilteredUsers.users = map(
filter(UserList.users, user -> user.isActive == true),
user -> {
name = upperCase(user.firstName + " " + user.lastName)
email = lowerCase(user.email)
joinDate = dateFormat("ms", "yyyy-MM-dd", user.createdAt)
}
)
FilteredUsers.count = length(FilteredUsers.users)
}

Testing Your Examples

All examples in this section can be tested using the Wolf DSL validation tools:

Maven Validation

mvn com.intuit.dsl.flow:wolf-maven-plugin:compile

Gradle Validation

./gradlew wollfValidate

IDE Validation

Open any .flow file in your IDE with the Wolf DSL plugin installed to see real-time syntax validation and error highlighting.

Example Template

When creating your own flows, use this template as a starting point:

// TODO: Replace with your schema definitions
Schema InputData {
string field1
// Add your fields here
}

Schema OutputData {
string result
// Add your fields here
}

// TODO: Replace with your data
value inputValue -> InputData {
field1: "example"
// Add your data here
}

// TODO: Replace with your transformation logic
Mapping transform input inputValue output OutputData {
OutputData.result = "Processed: " + inputValue.field1
// Add your mapping logic here
}

// TODO: Replace with your flow logic
Flow exampleFlow {
Start inputValue {
transition { transform }
}
transform {}
}

Best Practices

1. Clear Naming Conventions

//  Good: Descriptive names
Schema UserProfile { ... }
Service userProfileService method GET as getUserProfile
Mapping enrichUserProfileData

// Avoid: Generic names
Schema Data { ... }
Service svc1 method GET as getData
Mapping map1

2. Schema-First Design

//  Good: Define schemas first
Schema Order { ... }
Schema Customer { ... }
Schema OrderSummary { ... }

// Then use them
Mapping createOrderSummary input Order, Customer output OrderSummary

3. Configuration Externalization

//  Good: Use configuration
Service apiService {
Url -> @Config("api.base.url")
@Header ApiKey -> @Config("api.key")
}

// Avoid: Hardcoded values
Service apiService {
Url -> "https://hardcoded-api.com"
@Header ApiKey -> "secret-key-123"
}

4. Error Handling

//  Good: Plan for failures
Flow robustFlow {
Start request {
transition {
@Config("fallback.enabled") == "true"
? primaryService
: fallbackService
}
}
// Include timeout and retry configuration
primaryService {
Timeout -> ${10000}
Retry -> ${3}
}
}

Learning Path

  1. Start Here: Language Overview - Understanding core concepts
  2. Next: Service Node - Making API requests
  3. Then: Mapping Node - Processing and transforming data
  4. Advanced: Best Practices - Building resilient, maintainable flows
  5. Expert: Functions Reference - Master all available functions

Need Help?


These examples are tested against the Wolf DSL grammar and runtime. Copy any example and adapt it to your use case!