Posting JSON Data to a Mule Flow
There are only 11 steps to POSTing JSON data to a Mule flow. JSON data can be sent directly to a Mule flow. The reason for doing this is to access data from a payload.
Join the DZone community and get the full member experience.Join For Free
This is an example that showcases how data in JSON format can be sent directly to a Mule flow. The JSON data can be accessed using the Mule expression language inside the flow.
We will keep the flow simple, as accessing the data from the payload is the reason for this example.
11 Steps to POSTing JSON Data to a Mule Flow
Open Anypoint Studio.
Create a new Mule project. Click File > New > Mule Project.
Name the project JsonAccess and click Finish.
Drag the HTTP Connector from the palette onto the canvas. Click HTTP connector to open the properties window as shown below:
Click + to enter the connector settings.
Click OK. Now add
POSTagainst Method so that only
POSTis allowed on /.
Drag Logger from the palette next to the HTTP connector on the canvas. Click Logger the on canvas and enter
#[json:productid]as the value for the Message.
Save and your run project.
Open Postman. Prepare the request as shown in the image below:Make sure
POSTis selected as the method. Under the Body tab, choose raw and change mime to JSON (application/json). The content which we will
Click Send. Go back to Anypoint Studio.
Under Console, we can see the logger output as 6:
We have successfully
POSTed JSON data in the request body from Postman to the Mule application!
Opinions expressed by DZone contributors are their own.