🖱 How to create your first Mule 4 Application in 2021?

How to create your first Mule 4 Application?


Are you new to Mulesoft? You are here in the right place if you want to start developing the Mule applications. Use the below steps to start creating an application in Mule 4 AnyPoint Studio.

If you have not completed the MuleSoft Developer Certification, Read our article on MuleSoft Certified Developer Level 1 Tips

create mule4 application


 

1) Under src/main/mule , create a new Mule configuration file with name basics.xml

2) Select HTTP module in the mule palette, drag, and drop Http Listener Endpoint.

You will see that Connector Configuration is showing an error.

Click on “+” and configure a new HTTP Listener Configuration.  Give the Port number as 8081. Don't give any base path as of now.


Switch to XML mode and observe that the following line is outside the <flow> tag.
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="3068cd45-c638-430b-89e6-a512d3eb4f8a" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>

This is a global element that can be referred from any flow

Again double click on the HTTP component and configure the path (under Basic settings) as “ /hello”

3) Drag SetPayload transformer after HTTP Listener. Set Value as #[‘Hello World’]

4) Drag a Logger after SetPayload and set Message as #[ attributes.queryParams.name]

5) Run the application and give a request to the following URL in the browser

http://localhost:8081/hello?name=Uday

Observe the logs and see the name printed.

6) Now change the value for Set Payload to print Hello + query parameter name as shown below:

'Hello' ++ attributes.queryParams.name

Run the application and give the request to http://localhost:8081/hello?name=Uday

Did u get the response?

Now change the value for SetPayload as below and observe the response.

'Hello' ++ attributes.queryParams.name as String
7) Now change the path for Http Listener as /hello/{city}

Can you change the value for SetPayload  to concatenate  the value passed for city?

Hint :  'Hello' ++ attributes.queryParams.name as String ++ 'city : '++ attributes.uriParams.city 

8) We want to set a variable in the MuleEvent

Now Drag Set Variable transformer and configure a variable with name city and set its values as

attributes.uriParams.city 

9) In the Logger,  change the value to log the variable “city”

Run the application and give the request to http://localhost:8081/hello/Delhi?name=Uday
 

Comment here if you are facing any issues while creating the application. Also, let us know if you want us to write an article on the new topic. 

Find the latest MuleSoft (Mule 4) Articles on DataWeave, Anypoint Studio, Anypoint Platform, and Runtime Manager. Our articles also include frequently asked Mule4 Interview questions and answers. Please comment below for any queries or free article submissions.

Post a Comment

0 Comments