Back to EIP

PatternSplitter splits the message into multiple messages, each containing one of the elements.
How Ballerina helps

Ballerina supports arrays and maps as first-class data structures. These structures can be iterated over using foreach and query expressions.

SplitterContent FilterEvent Message
import ballerina/http;
import ballerina/mime;
import ballerina/url;

type ReminderRequest record {
    string date;
    Event[] events;

type Event record {|
    string eventName;
    Attendee[] attendees;

type Attendee record {|
    string name;
    string number;

const FROM_NO = "+15005550006";
const TWILIO_SID = "VAC1829a53d52f41b4b2b1cc003c0026aa8";
const API_VERSION = "2010-04-01";

final http:Client twilio = check new ("");

service /api/v1 on new http:Listener(8080) {
    resource function post reminders(ReminderRequest request) returns error? {
        foreach var event in {
            foreach var attendee in event.attendees {
                check sendReminder(attendee, event.eventName,;

function sendReminder(Attendee attendee, string eventName, string date) returns error? {
    string body = string `Hi ${}, looking forward to meet you at the ${eventName} on ${date}`;
    string payload = "From=" + check url:encode(FROM_NO, "utf-8") +
                     "&To=" + check url:encode(attendee.number, "utf-8") +
                     "&Body=" + check url:encode(body, "utf-8");
    http:Request twilioReq = new;
    twilioReq.setTextPayload(payload, contentType = mime:APPLICATION_FORM_URLENCODED);
    _ = check twilio->/[API_VERSION]/Accounts/[TWILIO_SID]/Messages\, targetType = http:Response);