Contact Free trial Login
Addition using a Javascript Transformer

Addition using a Javascript Transformer

(1 review)

This example shows how to parse an incoming JSON message and process it with the JavaScript transformer.

737d8550-addition-using-javascript-transformer.png

Example

In this example, you'll send a JSON message that contains two numbers to an HTTP endpoint. This Byte Array of data is transformed to a String. The JavaScript transformer then processes the data and adds up the numbers. Finally, the sum is returned to the HTTP endpoint.

Set up and Run the Example

  1. Open this example project in Anypoint Studio and run it.
  2. Use Postman, curl, or the REST console to make a POST request using JSON. The message body should contain the following data:{ "a": 3, "b": 4}
  3. If the project is running successfully, you should get the following message on your studio console.

INFO 2017-07-02 16:44:34,235 [[javascript-calculator].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Sum is: 7.0

Documentation

Read the full documentation in GitHub

Examples to Try Next

If you understood this example
Implementing a Choice Exception Strategy - Learn the concept of error handling in Mule by using a choice exception strategy.View
If you struggled with this example
HTTP Request Response with Logger - Learn how to use Mule to build a simple HTTP request-response application.View

Reviews

Download
Log into Anypoint Platform to download this asset

Overview

Type
Example
Organization
MuleSoft
Created by
MO
MuleSoft Organization
Published onOct 9, 2017

Versions

VersionRuntime version
1.5.03.x
1.4.03.x
1.3.33.7
1.2.03.6
Show more