Back to EIP

PatternContent enricher adds data that was not sent by the original sender to the message.
How Ballerina helps

Ballerina enables additional lookups to enrich the message, such as database lookups, REST API calls, etc. Spread operator (...) helps to create new records out of existing records while enriching them with additional data.

Content EnricherMessage ChannelMessage EndpointMessage
import ballerina/http;

type BankAccountReq record {|
    string name;
    string accountNumber;
    string routingNumber;
    string? country;

type IbanRequest record {|
    "json"|"xml" format = "json";
    string country_iso;
    string nid;

type IbanResponse record {
    string bank_code;

type BankAccount record {
    string id;
    string? bankCode;

final http:Client iban = check new ("");
final http:Client intuit = check new ("");

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

    resource function post customers/[int id]/accounts(BankAccountReq req) returns BankAccount|error {
        IbanRequest ibanReq = {country_iso: ?: "US", nid: req.accountNumber};
        IbanResponse ibanRes = check iban->/clients/api/banksuite/;
        return check intuit->/quickbooks/v4/customers/[id]/bank\{...req, bankCode: ibanRes.bank_code});