workflow.activity
Modules
Module workflow.activity
ballerina/workflow.activity Ballerina library
Functions
callRestAPI
function callRestAPI(Client connection, RestMethod method, string path, Request|map<json>|json|xml|string|byte[]? message, map<string|string[]>? headers, typedesc<anydata> t) returns t|errorCalls a REST API as a workflow activity.
The connection argument must be a module-level final http:Client
variable in the user's program. The compiler plugin generates the wiring
that makes it available on the activity worker side.
Example:
final http:Client api = check new ("https://api.example.com"); type User record {| int id; string name; |}; @workflow:Workflow isolated function myWorkflow(workflow:Context ctx) returns error? { User user = check ctx->callActivity(activity:callRestAPI, { connection: api, method: "GET", path: "/users/1" }); }
Parameters
- connection Client - The HTTP client to use for the call
- method RestMethod - HTTP method to invoke
- path string (default "") - Resource path appended to the client's base URL
- t typedesc<anydata> (default <>) - Expected payload type (inferred from context). The HTTP client performs data binding into this type.
Return Type
- t|error - Response payload as
t, or an error
callSoapAPI
function callSoapAPI(Client|Client connection, xml body, string? action, map<string|string[]> headers, string path) returns xml|errorCalls a SOAP endpoint as a workflow activity.
The connection argument must be a module-level final soap11:Client or
soap12:Client variable in the user's program. Both SOAP 1.1 and 1.2 clients
are supported. The action parameter is required for SOAP 1.1 and optional
for SOAP 1.2.
Example:
final soap11:Client calc = check new ("https://calc.example.com/svc?WSDL"); @workflow:Workflow isolated function addNumbers(workflow:Context ctx) returns error? { xml envelope = xml `<soap:Envelope ...><soap:Body>...</soap:Body></soap:Envelope>`; xml response = check ctx->callActivity(activity:callSoapAPI, { connection: calc, body: envelope, action: "http://tempuri.org/Add" }); }
sendEmail
function sendEmail(SmtpClient connection, string|string[] to, string subject, string 'from, string body, EmailOptions? options) returns error?Sends an email as a workflow activity.
The connection argument must be a module-level final email:SmtpClient
variable in the user's program. The activity sends the email using the
email:SmtpClient.send() method.
Example:
final email:SmtpClient smtp = check new ("smtp.example.com", "user", "pass"); @workflow:Workflow isolated function notifyWorkflow(workflow:Context ctx, string recipient) returns error? { check ctx->callActivity(activity:sendEmail, { connection: smtp, to: recipient, subject: "Order shipped", 'from: "no-reply@example.com", body: "Your order is on the way." }); }
Parameters
- connection SmtpClient - The SMTP client to use for sending
- subject string - Subject line of the email
- 'from string - From address of the email
- body string - Plain-text body of the email
- options EmailOptions? (default ()) - Optional email fields:
htmlBody,contentType,headers,cc,bcc,replyTo, andsender
Return Type
- error? - An error if sending fails, otherwise
()
Enums
workflow.activity: RestMethod
HTTP method supported by the callRestAPI builtin activity.
Members
Records
workflow.activity: EmailOptions
Additional email options for sendEmail.
Maps to the email:Options inclusive record accepted by email:SmtpClient.send().
All fields are optional; omitting a field leaves that aspect of the email unset.
Fields
- htmlBody? string - Optional HTML body (sent alongside the plain-text body)
- contentType? string - MIME content type override (default:
text/plain)
- sender? string - Sender address (used when the envelope sender differs from
From)
Import
import ballerina/workflow.activity;Metadata
Released date: 5 days ago
Version: 0.4.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.13.2
GraalVM compatible: No
Pull count
Total: 860
Current verison: 56
Weekly downloads
Keywords
workflow
Contributors