Getting Started With Anypoint Visualizer
Learn about Anypoint Visualizer and see a tutorial on how to create APIs and publish them to Exchange.
Join the DZone community and get the full member experience.
Join For FreeWhat Is Anypoint Visualizer?
Anypoint Visualizer displays views of different aspects. It provides a real-time, graphical representation of the API and Mule Application that are running and discoverable.
Anypoint Visualizer collects data from the Mule Application, and APIs and proxies deployed to CloudHub or Standalone Mule runtime engines to discover all incoming and outgoing connections through an embedded plugin.
This is what an Application Network Graph looks like in Anypoint Visualizer:
Let's see how to use Anypoint Visualizer with the help of an example for a better understanding. For this example, I have used the concept of a basic calculator, performing addition, subtraction, multiplication, and division.
Step 1: Creating APIs and Publishing Them to Exchange
A basic and common need to start building an application is to design it first. To perform calculations using the calculator, you need only three things: two numbers and an operation or an operand. The basic operations are addition, subtraction, multiplication, and division.
Therefore, we have to create 4 APIs for these operations. These APIs will be our backend APIs or System APIs.After that, I have divided these 4 APIs into 2 categories:
Simple Calculation, which contains addition and subtraction.
Advance Calculation, which contains multiplication and division.
These two APIs will be our Process APIs.
At last comes our main API, which is the Calculator API. It will be responsible for performing the calculations and will interact with the users or the outer world. This API will be our Experience API.
Therefore, we have to create a total of 7 APIs (4 System APIs, 2 Process APIs, 1 Experience API).
After creating each API in the design center, test it using the Mocking service and publish each of them to Anypoint Exchange as an asset. The APIs will be visible under your organization name as below:
Step 2: Manage the APIs in the API Manager
After publishing the APIs to Exchange, manage the APIs in the API Manager. I am managing these APIs in Mule 4. You can perform Anypoint Visualizer with Mule 3.9 also.
For more information, you can read the following in Mulesoft documentation here.
Step 3: Download RAML and Generate API Using Anypoint Studio
Download the RAML file from the design center to create a Mule project in Anypoint Studio. For each API, there will be a project; therefore, we will have a total of 7 Mule projects. We will now be implementing our main logic in these projects.
Code for Addition Project
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-gateway="http://www.mulesoft.org/schema/mule/api-gateway" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/api-gateway http://www.mulesoft.org/schema/mule/api-gateway/current/mule-api-gateway.xsd">
<http:listener-config name="addition-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="addition-config" raml="addition.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<api-gateway:autodiscovery apiId="15773341" doc:name="API Autodiscovery" doc:id="6adf501a-358a-4c41-b431-5622e6377000" flowRef="addition-main" />
<flow name="addition-main">
<http:listener config-ref="addition-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:router config-ref="addition-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="addition-console">
<http:listener config-ref="addition-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="addition-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\add:addition-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
add: attributes.queryParams.num1 + attributes.queryParams.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="df715fb3-c84b-4188-85ad-325a83b30b7a" message='#["Result is :" ++ payload.add]'/>
</flow>
<flow name="post:\add:addition-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="b9d784b5-e3cc-4c4f-9cdd-037824fb85bd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
add: payload.num1 + payload.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="e550c617-77a5-4aca-a09c-44959644299f" message='#["Result is :" ++ payload.add]'/>
</flow>
</mule>
Code for Subtraction Project
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-gateway="http://www.mulesoft.org/schema/mule/api-gateway" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/api-gateway http://www.mulesoft.org/schema/mule/api-gateway/current/mule-api-gateway.xsd">
<http:listener-config name="subtraction-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="subtraction-config" raml="subtraction.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<api-gateway:autodiscovery apiId="15773344" doc:name="API Autodiscovery" doc:id="fc4dc421-1097-4721-b3b0-fe558421caab" flowRef="subtraction-main" />
<flow name="subtraction-main">
<http:listener config-ref="subtraction-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body><![CDATA[#[payload]]]></http:body>
</http:error-response>
</http:listener>
<apikit:router config-ref="subtraction-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="subtraction-console">
<http:listener config-ref="subtraction-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="subtraction-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\sub:subtraction-config">
<http:listener doc:name="Listener" doc:id="fd17c26a-fa5b-49ca-8625-8cf08ff50e32" config-ref="subtraction-httpListenerConfig" path="/sub" allowedMethods="GET"/>
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="23f8cbdf-5b2b-4ed3-a285-8571d5435129">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
sub: attributes.queryParams.num1 - attributes.queryParams.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="f901331d-5809-4e06-8cfe-2f96044a3d9b" message='#["Result is :" ++ payload.sub]'/>
</flow>
<flow name="post:\sub:subtraction-config">
<http:listener doc:name="Listener" doc:id="54339d1b-dbbb-440c-9afe-57f5d05c982e" config-ref="subtraction-httpListenerConfig" path="/sub" allowedMethods="POST"/>
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="4b14e336-a483-4dec-ab3e-8236c21d17c3">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
sub: payload.num1 - payload.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="a498bf7e-21e0-4bf9-be3f-8138da6482ae" message='#["Result is :" ++ payload.sub]'/>
</flow>
</mule>
Code for Multiplication Project
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-gateway="http://www.mulesoft.org/schema/mule/api-gateway" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/api-gateway http://www.mulesoft.org/schema/mule/api-gateway/current/mule-api-gateway.xsd">
<http:listener-config name="multiply-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="multiply-config" raml="multiply.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<api-gateway:autodiscovery apiId="15773347" doc:name="API Autodiscovery" doc:id="b8b053ff-2367-4ee8-b2d3-102bfed30e89" flowRef="multiply-main" />
<flow name="multiply-main">
<http:listener config-ref="multiply-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body><![CDATA[#[payload]]]></http:body>
</http:error-response>
</http:listener>
<apikit:router config-ref="multiply-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="multiply-console">
<http:listener config-ref="multiply-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="multiply-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\multiply:multiply-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="ae8d15e5-f7dc-4b18-8973-08eba8551b2c">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
mul: attributes.queryParams.num1 * attributes.queryParams.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="8a1df8af-e16b-4c67-8cd8-4733362bca50" message='#["Result is :" ++ payload.mul]'/>
</flow>
<flow name="post:\multiply:multiply-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="40912298-1d7b-4816-bd04-5112e4bce0bd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
mul: payload.num1 * payload.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="379ff92e-c2de-4b09-8a18-146e4c5db162" message='#["Result is :" ++ payload.mul]'/>
</flow>
</mule>
Code for Division Project
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-gateway="http://www.mulesoft.org/schema/mule/api-gateway" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/api-gateway http://www.mulesoft.org/schema/mule/api-gateway/current/mule-api-gateway.xsd">
<http:listener-config name="division-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="division-config" raml="division.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<api-gateway:autodiscovery apiId="15773348" doc:name="API Autodiscovery" doc:id="fa680d72-60c3-4656-a7dd-5ee164ac6b00" flowRef="division-main" />
<flow name="division-main">
<http:listener config-ref="division-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:router config-ref="division-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="division-console">
<http:listener config-ref="division-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="division-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\div:division-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="b3160ab8-aef1-4993-b4ac-9569a54c1c54">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
div: attributes.queryParams.num1 / attributes.queryParams.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="5e4df39d-c445-4b4b-bab4-c71cd35cd2ff" message='#["Result is :" ++ payload.div]'/>
</flow>
<flow name="post:\div:division-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="c3cdcce6-97d5-44c6-8dcf-cb824277eefc">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
div: payload.num1 / payload.num2
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="1565dd40-7d11-4237-8cfd-f74c5535c6bb" message='#["Result is :" ++ payload.div]'/>
</flow>
</mule>
Code for Simple Calculator
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-gateway="http://www.mulesoft.org/schema/mule/api-gateway" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/api-gateway http://www.mulesoft.org/schema/mule/api-gateway/current/mule-api-gateway.xsd">
<http:listener-config name="simplecalculator-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="simplecalculator-config" raml="simplecalculator.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="db7aad4a-9b25-4959-8ca4-4e98fd5ab30f" >
<http:request-connection host="addition.us-e2.cloudhub.io" />
</http:request-config>
<http:request-config name="HTTP_Request_configuration1" doc:name="HTTP Request configuration" doc:id="d7324cb0-1bc5-48b0-8671-af67c85ed4b7" >
<http:request-connection host="subtraction.us-e2.cloudhub.io" />
</http:request-config>
<api-gateway:autodiscovery apiId="15775220" doc:name="API Autodiscovery" doc:id="11045e81-055b-49fa-afc0-f709c5cf665e" flowRef="simplecalculator-main" />
<flow name="simplecalculator-main">
<http:listener config-ref="simplecalculator-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:router config-ref="simplecalculator-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="simplecalculator-console">
<http:listener config-ref="simplecalculator-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="simplecalculator-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\simple-cal:simplecalculator-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="6f7fee3c-7ca5-40b0-bb23-57d72525c5b8">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: attributes.queryParams.num1,
param2: attributes.queryParams.num2,
func: attributes.queryParams.operation
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="e70fa884-8f2e-4125-bff9-b244974ee16d" >
<when expression='#[payload.func == "add"]'>
<http:request method="GET" doc:name="Request" doc:id="72df3470-f834-485a-b283-5da6a4cc7bec" config-ref="HTTP_Request_configuration" path="/api/add">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="b8e47aeb-ae65-4eb2-a300-9f3f74670396" message='#["Result is :" ++ payload.add]' />
</when>
<otherwise >
<http:request method="GET" doc:name="Request" doc:id="1795f09f-f776-47ba-95a8-3b96d46f5ef5" config-ref="HTTP_Request_configuration1" path="/api/sub">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="f3f7e568-4979-46a2-a0db-d1c82dfdc857" message='#["Result is :" ++ payload.sub]'/>
</otherwise>
</choice>
</flow>
<flow name="post:\simple-cal:simplecalculator-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="8933c20f-7195-4c0d-8c52-b128e1dcf354">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: payload.num1,
param2: payload.num2,
func: payload.operation
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="50d0cac5-18aa-4cca-991c-c22d4395b6e7" >
<when expression='#[payload.func == "add"]'>
<http:request method="GET" doc:name="Request" doc:id="da8977a1-21a7-4173-9611-4a35fa04b8b7" config-ref="HTTP_Request_configuration" path="/api/add" >
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="247885db-2538-4c33-a1bc-da1a893efed1" message='#["Result is :" ++ payload.add]' />
</when>
<otherwise>
<http:request method="GET" doc:name="Request" doc:id="5252d2f6-36b9-4f0b-a6e1-282d993e9e7b" config-ref="HTTP_Request_configuration1" path="/api/sub">
<http:query-params><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="704576da-6270-4b1e-ae7b-58a31bedbec3" message='#["Result is :" ++ payload.sub]'/>
</otherwise>
</choice>
</flow>
</mule>
Code for Advance Calculator
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-gateway="http://www.mulesoft.org/schema/mule/api-gateway" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/api-gateway http://www.mulesoft.org/schema/mule/api-gateway/current/mule-api-gateway.xsd">
<http:listener-config name="advancecalculator-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="advancecalculator-config" raml="advancecalculator.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="4b26f8ba-20d2-4a1e-a8fe-10ca5c3fcad6" >
<http:request-connection host="multiplication.us-e2.cloudhub.io" />
</http:request-config>
<http:request-config name="HTTP_Request_configuration2" doc:name="HTTP Request configuration" doc:id="8ec2662a-5294-4a7b-beed-df086ff343d0" >
<http:request-connection host="division.us-e2.cloudhub.io" />
</http:request-config>
<api-gateway:autodiscovery apiId="15775270" doc:name="API Autodiscovery" doc:id="1af7a87a-ac3e-4363-a321-8cbeb47eab91" flowRef="advancecalculator-main" />
<flow name="advancecalculator-main">
<http:listener config-ref="advancecalculator-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:router config-ref="advancecalculator-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="advancecalculator-console">
<http:listener config-ref="advancecalculator-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="advancecalculator-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\advance-cal:advancecalculator-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="65d91a4f-af70-4bc3-98a3-847df2365317">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: attributes.queryParams.num1,
param2: attributes.queryParams.num2,
func: attributes.queryParams.operation
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="bf696bfd-e604-4c41-96e2-5c2736e7ba00" >
<when expression='#[payload.func == "multiply"]'>
<http:request method="GET" doc:name="Request" doc:id="06e6c876-f3e8-48a2-98b9-adf589ef861f" path="/api/multiply" config-ref="HTTP_Request_configuration">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="ea28d23e-391d-4ce4-ab8f-d8ed320daf50" message='#["Result is :" ++ payload.mul]'/>
</when>
<otherwise >
<http:request method="GET" doc:name="Request" doc:id="b46790ce-d561-4abf-b282-ad2e0925b22d" config-ref="HTTP_Request_configuration2" path="/api/div">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="209a5824-1a0f-406a-896d-6bd18393174e" message='#["Result is :" ++ payload.div]'/>
</otherwise>
</choice>
</flow>
<flow name="post:\advance-cal:advancecalculator-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="753432e1-0d80-4e3e-98a1-35ded4cff927">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: payload.num1,
param2: payload.num2,
func: payload.operation
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="4759b669-b11b-452f-a4da-d4abb4b56516" >
<when expression='#[payload.func == "multiply"]'>
<http:request method="GET" doc:name="Request" doc:id="2aedb12a-ad43-4c19-a71e-202831a33ce9" path="/api/multiply" config-ref="HTTP_Request_configuration">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="f5b8fb6b-08f8-4617-85a4-1f16b7e201ff" message='#["Result is :" ++ payload.mul]'/>
</when>
<otherwise >
<http:request method="GET" doc:name="Request" doc:id="2a1e35bf-646c-4e06-b459-a7de967c2814" path="/api/div" config-ref="HTTP_Request_configuration2">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="c043b0fc-f30a-4b81-9694-eb649ba101f5" message='#["Result is :" ++ payload.div]'/>
</otherwise>
</choice>
</flow>
</mule>
Code for Calculator
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-gateway="http://www.mulesoft.org/schema/mule/api-gateway" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/api-gateway http://www.mulesoft.org/schema/mule/api-gateway/current/mule-api-gateway.xsd">
<http:listener-config name="calculator-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<apikit:config name="calculator-config" raml="calculator.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="8d5ae27f-ee4b-424d-b111-1daffe65ef8c" >
<http:request-connection host="simplecal.us-e2.cloudhub.io" />
</http:request-config>
<http:request-config name="HTTP_Request_configuration1" doc:name="HTTP Request configuration" doc:id="e7543560-0874-4725-82e0-e68bbc0c12e0" >
<http:request-connection host="advancecal.us-e2.cloudhub.io" />
</http:request-config>
<api-gateway:autodiscovery apiId="15775575" doc:name="API Autodiscovery" doc:id="80fe8488-e6da-439d-a471-8dfe698c3b32" flowRef="calculator-main" />
<flow name="calculator-main">
<http:listener config-ref="calculator-httpListenerConfig" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:router config-ref="calculator-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">400</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">405</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">406</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">415</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">501</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="calculator-console">
<http:listener config-ref="calculator-httpListenerConfig" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="calculator-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\cal:calculator-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="0718b324-ad52-44d6-a83d-89c5bac69156">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
n1: attributes.queryParams.num1,
n2: attributes.queryParams.num2,
result: attributes.queryParams.function
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="0d39af95-333c-4019-9529-bb645ab3da65" >
<when expression='#[payload.result == "add" or payload.result == "sub"]' doc:id="4b6476a6-186c-41f2-abb3-fb25c0d08dac">
<ee:transform doc:name="Transform Message" doc:id="75113e27-bf41-4c23-aec1-3dc1b11ad411">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: payload.n1,
param2: payload.n2,
func: payload.result
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="eec9f336-0fd2-49ff-8214-66bcb95f9710" >
<when expression='#[payload.func == "add"]'>
<http:request method="GET" doc:name="Request" doc:id="79ccb5d9-14c6-448d-bf05-e2bf77aa516e" path="/api/simple-cal" config-ref="HTTP_Request_configuration">
<http:query-params><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="1bc5cacf-9991-46ab-bfa8-3f86d89cbb29" message='#["Result is :" ++ payload.add]'/>
</when>
<otherwise>
<http:request method="GET" doc:name="Request" doc:id="4bcd8deb-827a-4228-ba7f-cdd09370ee4b" path="/api/simple-cal" config-ref="HTTP_Request_configuration">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="13cefd7b-d68a-4e97-9b90-f2bbf1acbff8" message='#["Result is :" ++ payload.sub]'/>
</otherwise>
</choice>
</when>
<when expression='#[payload.result == "multiply" or payload.result == "div"]'>
<ee:transform doc:name="Transform Message" doc:id="c6b70294-9ff7-4f1b-b918-46fa9e5349aa">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: payload.n1,
param2: payload.n2,
func: payload.result
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="0509bf13-abf4-40f8-948a-3ff59a0334c0">
<when expression='#[payload.func == "multiply"]'>
<http:request method="GET" doc:name="Request" doc:id="ec846db1-592e-4af4-a11c-9ae67f6cba63" path="/api/advance-cal" config-ref="HTTP_Request_configuration1">
<http:query-params><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="da5305b4-4978-44aa-8f20-b3f4b3b66c52" message='#["Result is :" ++ payload.mul]' />
</when>
<otherwise>
<http:request method="GET" doc:name="Request" doc:id="205301eb-3150-4e3c-846c-c534eabc8821" path="/api/advance-cal" config-ref="HTTP_Request_configuration1">
<http:query-params><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="f5658704-fcfd-461f-b76b-fa9a015285d7" message='#["Result is :" ++ payload.div]' />
</otherwise>
</choice>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger" doc:id="54fbdaa2-cdc9-446a-90f6-7983ace17c4a" message='#["Wrong operation selected. PLease select ADD, SUB, MULTIPLY or DIVIDE"]'/>
</otherwise>
</choice>
</flow>
<flow name="post:\cal:calculator-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="729e9be0-fbbd-4639-85aa-cef07166e94e">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
n1: payload.num1,
n2: payload.num2,
result: payload.function
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="fb3b6794-9fe3-44c2-8f79-31152d6250d1" >
<when expression='#[payload.result == "add" or payload.result == "sub"]' doc:id="4b6476a6-186c-41f2-abb3-fb25c0d08dac" >
<ee:transform doc:name="Transform Message" doc:id="b06cd82a-d6fe-4973-85e0-fff6561ec393">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: payload.n1,
param2: payload.n2,
func: payload.result
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="6e5eba5f-85df-486a-8417-047ff899a84c" >
<when expression='#[payload.func == "add"]' >
<http:request method="GET" doc:name="Request" doc:id="29869b67-9f08-4d29-ae99-a13d3e41e3b8" path="/api/simple-cal" config-ref="HTTP_Request_configuration">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="df27c56c-6ee2-4284-b036-90d62da4d899" message='#["Result is :" ++ payload.add]' />
</when>
<otherwise >
<http:request method="GET" doc:name="Request" doc:id="9ed15c3e-afa5-4d56-af56-350ad5b882ac" path="/api/simple-cal" config-ref="HTTP_Request_configuration">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="23c48b6c-f646-4cc1-92c4-4b80b8c57284" message='#["Result is :" ++ payload.sub]' />
</otherwise>
</choice>
</when>
<when expression='#[payload.result == "multiply" or payload.result == "div"]' >
<ee:transform doc:name="Transform Message" doc:id="f67e5a2b-fda1-4475-9b57-6f1cade3961f">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
param1: payload.n1,
param2: payload.n2,
func: payload.result
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<choice doc:name="Choice" doc:id="fd727bfa-0735-4cdc-9631-d742722f7e89" >
<when expression='#[payload.func == "multiply"]' >
<http:request method="GET" doc:name="Request" doc:id="350d54b6-c5c7-4a7b-853c-061039b5e5d5" path="/api/advance-cal" config-ref="HTTP_Request_configuration1">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="78aee76e-938a-4c22-a396-7b7a2a02455e" message='#["Result is :" ++ payload.mul]' />
</when>
<otherwise >
<http:request method="GET" doc:name="Request" doc:id="0cb12d46-1693-491f-99a6-c3a9c813e49d" path="/api/advance-cal" config-ref="HTTP_Request_configuration1">
<http:query-params ><![CDATA[#[output application/java
---
{
num1 : payload.param1,
num2 : payload.param2,
operation : payload.func
}]]]></http:query-params>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="06194a20-0b6d-46a6-a78a-29f7c6be9896" message='#["Result is :" ++ payload.div]' />
</otherwise>
</choice>
</when>
<otherwise >
<logger level="INFO" doc:name="Logger" doc:id="d5060961-0ca8-49a6-9d24-9b812b51a727" message='#["Wrong operation selected. PLease select ADD, SUB, MULTIPLY or DIVIDE"]' />
</otherwise>
</choice>
</flow>
</mule>
Step 4: Deploy the Projects to CloudHub
After creating the projects, deploy them to CloudHub. In these projects, I have used the API Autodiscovery scheme to pair our API in the API manager to its deployed Mule application. It is optional here. You can use it or skip it; it's up to you.
After deploying each project, check the status of each project in the Runtime Manager. All the projects will be in a started state.
Step 5: Setting up the Anypoint Visualizer
1. Go to the Access Management tab in the Anypoint Platform.
2. Select the Users tab on the left side panel and click on your username.
3. Select the Visualizer tab and provide access to the Visualizer Editor.
4. Enable Anypoint Monitoring too, present on the right side of the Visualizer tab.
5. Go to the Anypoint Visualizer tab in Anypoint Platform and select your Environment (sandbox).
6. Select all of your projects and it will be visible in the Visualizer tab.
Step 6: Assign Layers to the Nodes
Click on any one of the nodes. A window appears on the left side of the screen providing the details about the nodes.
In the layer drop-down menu, you can assign nodes to the layers.
Addition, subtraction, multiplication, and division will be in our SYSTEM LAYER.
The simple calculator and advanced calculator will be in our PROCESS LAYER.
The calculator will be in our EXPERIENCE LAYER.
Step 7: Making a Call From an External Client (Using Postman or Arc)
Make a call using Postman or Arc to the calculator application, providing two numbers and an operation. The operation can be any operation in the system layer.
You will see that you are getting the output without interacting with the system layer. The user interacts with the experience layer, and the visualizer will display the path through which the request passes to the backend application.
Make multiple calls to different applications using the process layer or without using the process layer (direct call to the system layer).
POST URL:
GET URL:
This is how our application network graph will look after the completion of multiple requests:
Thank you!
Opinions expressed by DZone contributors are their own.
Comments