Lemline documentation Help

Lemline Integration Examples

Run the Examples

Complete the SQLite setup and keep its worker running. Run the commands from a second terminal in the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. Start the tutorial shop from the root of the Lemline source checkout:

docker compose -f examples/tutorial-services/compose.yaml up -d

This document provides examples of integrating Lemline workflows with external services using various protocols and standards. These integration patterns enable workflows to interact with APIs, services, and messaging systems.

HTTP/REST API Integration

HTTP/REST is one of the most common integration methods for connecting workflows to external services.

Basic HTTP Call

document: dsl: '1.0.3' namespace: examples name: call-http-shorthand-endpoint version: '0.1.0' do: - getProduct: call: http with: method: get endpoint: '${ "http://127.0.0.1:8787/products/" + .productId }'

Save it as basic-http-call.yaml:

bin/lemline definition post -f basic-http-call.yaml bin/lemline instance start examples call-http-shorthand-endpoint --input '{"productId":"SKU-3"}'

Expect the pruning shears: {"id":"SKU-3","name":"Pruning shears","category":"garden","price":18,"available":10}.

This example demonstrates:

  • A simple HTTP GET request

  • A URI built from the productId workflow input with a runtime expression

HTTP with Query Parameters

document: dsl: '1.0.3' namespace: examples name: http-query-params version: '1.0.0' input: schema: format: json document: type: object required: - searchQuery properties: searchQuery: type: string do: - searchProducts: call: http with: method: get endpoint: http://127.0.0.1:8787/products query: search: ${ .searchQuery }

Save it as http-with-query-parameters.yaml:

bin/lemline definition post -f http-with-query-parameters.yaml bin/lemline instance start examples http-query-params --input '{"searchQuery":"hose"}' bin/lemline instance start examples http-query-params --input '{}'

The first instance returns one page with the garden hose (items lists SKU-1, total is 1). The second is refused by the input schema before any instance exists: Missing required field(s): 'searchQuery'.

This example shows:

  • Using query parameters with the query property

  • Dynamic query values using expressions

  • Input schema validation

HTTP with Authentication

document: dsl: '1.0.3' namespace: examples name: http-with-oauth2 version: '0.1.0' use: secrets: - clientSecret do: - getPartnerStock: call: http with: method: get endpoint: uri: http://127.0.0.1:8787/partner/stock authentication: oauth2: authority: http://127.0.0.1:8787 endpoints: token: /oauth2/token grant: client_credentials client: id: shop-workflows secret: ${ $secrets.clientSecret }

Lemline registers this definition but cannot run it: the instance faults with Unsupported OAuth2 authentication before any request. See Configuring OAuth 2.0 Authentication to see it, and How to use API keys for the methods that work: bearer token, basic authentication and keys in headers or query parameters.

This example demonstrates:

  • OAuth2 authentication for HTTP calls

  • Client credentials grant type

  • Custom token endpoints

OpenAPI Integration

OpenAPI integration allows workflows to interact with services described by OpenAPI specifications.

Basic OpenAPI Call

document: dsl: '1.0.3' namespace: examples name: openapi-list-products version: '0.1.0' do: - findGardenProducts: call: openapi with: document: endpoint: http://127.0.0.1:8787/openapi.json operationId: listProducts parameters: category: garden

Save it as basic-openapi-call.yaml:

bin/lemline definition post -f basic-openapi-call.yaml bin/lemline instance start examples openapi-list-products

The definition registers; the instance faults with Unknown task type: CallOpenAPI. How to describe an OpenAPI call shows the same operation written as an HTTP call.

This example demonstrates:

  • Referencing an OpenAPI specification document

  • Calling an operation by its operationId

  • Passing operation parameters

Benefits of using OpenAPI integration:

  • Type-safe API interactions

  • Automatic request/response serialization

  • Simplified parameter handling

  • API discoverability

gRPC Integration

gRPC integration enables workflows to communicate with gRPC services.

Basic gRPC Call

document: dsl: '1.0.3' namespace: examples name: grpc-get-stock version: '0.1.0' do: - getStock: call: grpc with: proto: endpoint: file:///opt/shop/inventory.proto service: name: shop.InventoryService host: localhost port: 50051 method: GetStock arguments: sku: ${ .sku }

Save it as basic-grpc-call.yaml:

bin/lemline definition post -f basic-grpc-call.yaml bin/lemline instance start examples grpc-get-stock --input '{"sku":"SKU-1"}'

The definition registers; the instance faults with Unknown task type: CallGRPC. The shop has no gRPC server.

This example demonstrates:

  • Referencing a Protocol Buffers (.proto) file

  • Specifying the service name, host, and port

  • Calling a specific method

  • Passing arguments from workflow data

Benefits of using gRPC:

  • Efficient binary communication

  • Strongly typed contracts

  • Support for streaming (unary, server, client, or bidirectional)

  • Built-in compression

AsyncAPI Integration

AsyncAPI integration allows workflows to interact with event-driven and message-based systems.

Publishing Messages

document: dsl: '1.0.3' namespace: examples name: asyncapi-publish version: '0.1.0' do: - findPet: call: asyncapi with: document: endpoint: https://events.example.com/docs/asyncapi.json operation: findPetsByStatus server: name: staging message: payload: petId: ${ .pet.id } authentication: bearer: token: ${ .token }

Lemline has no AsyncAPI executor: the task fails with Unknown task type: CallAsyncAPI. To publish an event from a workflow, use an emit task.

This example demonstrates:

  • Referencing an AsyncAPI specification

  • Publishing a message to a specific server

  • Specifying the message payload

  • Including authentication

Subscribing to Messages

document: dsl: '1.0.3' namespace: examples name: asyncapi-subscribe version: '0.1.0' do: - getNotifications: call: asyncapi with: document: endpoint: https://events.example.com/docs/asyncapi.json operation: getNotifications protocol: ws subscription: filter: '${ .correlationId == $context.userId and .payload.from.firstName == $context.contact.firstName and .payload.from.lastName == $context.contact.lastName }' consume: amount: 5

This one fails the same way. To wait for events, use a listen task.

This example demonstrates:

  • Subscribing to messages using WebSocket protocol

  • Applying a filter expression to incoming messages

  • Consuming a specific amount of messages

Other Subscription Patterns

AsyncAPI integration supports various message consumption patterns:

  1. Consume a specific amount:

    subscription: consume: amount: 5
  2. Consume until a condition is met:

    subscription: consume: until: '${ .status == "completed" }'
  3. Consume while a condition is true:

    subscription: consume: while: '${ .status == "processing" }'

Add consume.for to limit how long an amount, while or until policy can run. Use subscription.foreach to process each consumed message.

Custom Function Integration

Custom functions allow reusing integration patterns across workflows.

Inline Custom Function

document: dsl: '1.0.3' namespace: examples name: call-custom-function-inline version: '0.1.0' use: functions: getProductById: input: schema: document: type: object properties: productId: type: string required: [ productId ] call: http with: method: get endpoint: '${ "http://127.0.0.1:8787/products/" + .productId }' do: - getProduct: call: getProductById with: productId: SKU-2

Save it as inline-custom-function.yaml:

bin/lemline definition post -f inline-custom-function.yaml bin/lemline instance start examples call-custom-function-inline

The function validates its input, then calls the shop: expect the watering can, {"id":"SKU-2","name":"Watering can","category":"garden","price":12,"available":10}.

This example demonstrates:

  • Defining a custom function inline

  • Adding input schema validation

  • Reusing the function within the workflow

Cataloged Function

Custom functions can also be defined in a separate catalog and referenced across multiple workflows:

document: dsl: '1.0.3' namespace: examples name: call-custom-function-cataloged version: '0.1.0' use: catalogs: shop-catalog: endpoint: http://127.0.0.1:8787/catalog/ do: - getProduct: call: get-product:1.0.0@shop-catalog with: productId: SKU-2

Save it as cataloged-function.yaml:

bin/lemline definition post -f cataloged-function.yaml bin/lemline instance start examples call-custom-function-cataloged

A catalog function is called as name:version@catalog, with lowercase names. The catalog endpoint is the catalog root: Lemline reads get-product:1.0.0@shop-catalog from http://127.0.0.1:8787/catalog/functions/get-product/1.0.0/function.yaml, which the tutorial shop serves. That definition is the same as the inline function: it validates productId, then calls the shop. Expect the watering can, {"id":"SKU-2","name":"Watering can","category":"garden","price":12,"available":10}. Catalog endpoints can also be file:// URLs; an endpoint with authentication is not supported yet.

This enables:

  • Function reuse across multiple workflows

  • Centralized integration pattern maintenance

  • Consistent API access patterns

Best Practices for Integrations

When implementing integration patterns in Lemline:

  1. Error handling: Always implement error handling for external service calls using try-catch blocks

  2. Timeouts: Set appropriate timeouts for service calls to prevent workflow hangs (Lemline only enforces timeouts on listen tasks; HTTP calls use fixed limits of 15 s to connect and 30 s per request)

  3. Retry strategies: Use retry mechanisms with backoff for transient failures

  4. Authentication: Securely manage credentials using secrets management

  5. Data validation: Validate inputs and outputs using schemas

  6. Monitoring: Add appropriate logging for external service interactions

  7. Idempotency: Design integrations to be idempotent to handle retries safely

Complex Integration Example

This example combines several integration patterns that Lemline runs:

document: dsl: '1.0.3' namespace: examples name: complex-integration version: '1.0.0' use: functions: getCustomer: call: http with: method: get endpoint: '${ "http://127.0.0.1:8787/customers/" + .customerId }' do: - getCustomerData: call: getCustomer with: customerId: ${ .customerId } export: as: '${ $context + { customerData: . } }' - processPurchaseOrder: try: - validateInventory: call: http with: method: post endpoint: http://127.0.0.1:8787/reservations body: orderId: ${ $workflow.input.orderId } items: ${ $workflow.input.orderItems } - processPayment: call: http with: method: post endpoint: http://127.0.0.1:8787/charges body: orderId: ${ $workflow.input.orderId } paymentInfo: token: ${ $workflow.input.paymentToken } - notifyShipping: emit: event: with: type: com.example.shipping.requested source: https://events.example.com/order-service data: orderId: ${ $workflow.input.orderId } customer: ${ $context.customerData.name } items: ${ $workflow.input.orderItems } catch: as: error do: - routeByErrorType: switch: - paymentDeclined: when: ${ $error.status == 402 } then: notifyCustomer - default: then: logError - notifyCustomer: call: http with: method: post endpoint: http://127.0.0.1:8787/notifications body: reference: ${ $workflow.input.orderId } recipient: customer message: Your payment was declined. Please update payment information. then: exit - logError: call: http with: method: post endpoint: http://127.0.0.1:8787/audit body: reference: ${ $workflow.input.orderId } message: ${ $error.title }

Save it as complex-integration-example.yaml:

bin/lemline definition post -f complex-integration-example.yaml bin/lemline instance start examples complex-integration --input '{"orderId":"ORD-1101","customerId":"C-100","orderItems":[{"id":"SKU-1","quantity":1}],"paymentToken":"approved"}' bin/lemline instance start examples complex-integration --input '{"orderId":"ORD-1102","customerId":"C-100","orderItems":[{"id":"SKU-1","quantity":1}],"paymentToken":"declined"}' bin/lemline instance start examples complex-integration --input '{"orderId":"ORD-1103","customerId":"C-100","orderItems":[{"id":"SKU-1","quantity":500}],"paymentToken":"approved"}'

Order

What happens

Where to see it

ORD-1101

Stock reserved, payment approved, com.example.shipping.requested emitted with the customer name

The shop's reservations and charges

ORD-1102

The charge answers HTTP 402; the error routes to notifyCustomer

A customer inbox entry for ORD-1102

ORD-1103

The reservation answers HTTP 409; the error routes to logError

An audit entry for ORD-1103 starting with HTTP 409

All three instances complete. Stop the shop when you are done:

docker compose -f examples/tutorial-services/compose.yaml down

This complex example demonstrates:

  • A reusable function declared under use.functions

  • HTTP calls to several shop services

  • An event emitted for the shipping service

  • Error routing on the failure that occurred

  • Data shared through $context

Conclusion

These integration examples showcase Lemline's ability to connect with various external services and systems. By leveraging these patterns, you can build workflows that:

  • Integrate with diverse APIs and services

  • Process events and messages

  • Reuse integration logic across workflows

  • Handle errors and retries gracefully

  • Ensure secure communication with external systems

For examples of error handling and resilience patterns, see the Error Handling Examples document.

25 November 2026