Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Foreach mediator #2252

Merged
merged 1 commit into from
Dec 16, 2024
Merged

Conversation

SanojPunchihewa
Copy link
Contributor

Purpose

Add new Foreach mediator which will iterate collection referred using body or variable and update the original collection or output the result to a variable.

Syntax

<foreach collection="expression" parallel-execution=(true | false) result-target=(variable) result-type="JSON" >
        <sequence>
        (mediator)+
        </sequence>+
</foreach>

Sample configuration

  1. Output iteration results to variable
<foreach collection="${payload.data.list}" result-target="fileList" result-type="JSON" parallel-execution="true">
    <sequence>
        <log category="INFO">
            <message>Processing message : ${payload} with counter : ${var.counter}</message>
        </log>
        <payloadFactory media-type="json">
            <format><![CDATA[{
                "_name": ${payload.name},
                "age": 5
                }]]>
                </format>
        </payloadFactory>
        <call> 
            <endpoint>
                <http method="post" uri-template="http://localhost:5454/api/pet1"/>
            </endpoint>
        </call>
    </sequence>
</foreach>
  1. Update the original collection
<foreach collection="${var.folderList}" parallel-execution="true">
    <sequence>
        <log category="INFO">
            <message>Processing message : ${payload}</message>
        </log>
        <call>
            <endpoint>
                <http method="post" uri-template="http://localhost:5454/api/transform">
                </http>
            </endpoint>
        </call>
    </sequence>
</foreach>

@SanojPunchihewa SanojPunchihewa merged commit 65e169c into wso2:master Dec 16, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants