Back to EIP

PatternThe content filter removes data from the original message and can also be employed to simplify the message structure.
How Ballerina helps

Ballerina excels at manipulating data and handling diverse formats, structures, and transformations. The query expression (from keyword) is useful for transforming messages. The select clause, as shown below, can be used to create new records from existing ones while refining data. The where clause can be used to filter items from an array.

Content FilterMessage ChannelMessage Endpoint
Copy
import ballerina/http;

type DetailedReimbursementTemplate record {
    string reimbursementTypeID;
    string reimbursementTypeName;
    float fixedAmount;
};

type ReimbursementTemplate record {
    string reimbursementTypeID;
    float fixedAmount;
};

type Reimbursement record {
    string id;
    record {
        string reimbursementTypeID;
        float fixedAmount;
    }[] reimbursementTemplates;
};

final http:Client xero = check new ("http://api.xero.com.balmock.io");

service /payroll on new http:Listener(8080) {

    resource function post employees/[string id]/paytemplate/reimbursements(DetailedReimbursementTemplate[] templates)
            returns Reimbursement|error {
        ReimbursementTemplate[] reimbursementRequests = from var {reimbursementTypeID, fixedAmount} in templates
                                                        select {reimbursementTypeID, fixedAmount};
        return xero->/payrollxro/employees/[id]/paytemplate/reimbursements.post(reimbursementRequests);
    }
}