Monday, December 1, 2014

WSO2 ESB Script Mediator Using JavaScript with a Json payload

Synapse supports Mediators implemented in a variety of scripting languages such as JavaScript, Groovy, or Ruby. For More information on script mediator please refer this link.

This blog post will explain a scenario of using script mediator with a Json payload.

Configure back-end

1. Deploy this webapp in an appserver.

Configure ESB

2. Provide the following api synapse configuration.

<api name="pizzashop" context="/pizzashop">
 <resource methods="GET" uri-template="/api/menu/pizza*">
     <http method="get"
   <log level="full"/>
    <script language="js">var payload = mc.getPayloadJSON();mc.setPayloadJSON(payload);    </script>

Invoking the service

3. Invoke the service

curl -v "http://localhost:8280/pizzashop/api/menu/pizza/all"

You will get all the available pizza list.