Author: Abhinav Patel
Welcome all, to the series of the HTML rendering in Mule. With this series, I am introducing you all with the whole new world of services that could be created using Mulesoft tools.
If you have not gone through the previous article, I would recommend you go through it first, to get a basic understanding of HTML rendering and its requirements. In this article, we will try to understand the working of Parse Template.
Before we move ahead let us be aware that for this part of blog we will be placing all the HTML pages under src/main/resources in the project as shown below
Also, all the HTTP configuration values will be kept as default.
For this blog, we will be creating two flows
- Form Flow
- Response Flow
Form Flow helps us to demonstrate the use of a Parse Template in an application so as to render an HTML static page that takes user inputs fname and lname with default value as “max” and “mule”.
Response Flow demonstrates the use of a Parse Template in an application that accepts query parameter fname and lname, and displays that in tabular format.
Now there are multiple methods to define your HTML responses in Parse Template, either you can make use of the Content field which uses a string or Location field which uses an external file. Both contain embedded expressions to be evaluated and replaced on runtime.
Remember to do the configuration in Parse Template:General > settings > location > form.html
The form.html file that I have made use of is shown below : –
Now we will create another flow to send back the response to the user
Remember to do the configuration in Parse Template: General > settings > location > response.html
The body of response.html file that I have made use of is shown below : –
We can observe that response.html is defined as text with embedded Mule expressions that are evaluated and replaced with their result at runtime once the application is executed.
Our simple application is ready to be deployed. So, let’s run the application and test it. Once the application is deployed, make a call to http://localhost:8081/form. And we will be able to see the response as shown below
The response flow is listening on path “http://localhost:8081/form” as shown in the form.html.
Keeping the values as default if we click on the response button, we will be able to see the response as shown below:
Also if we check our console window in Anypoint studio we will be able to see the query parameters as shown below:
I hope you got to learn something new from this walkthrough. Do post your responses as a comment to let me know that your application is running.
Also, in the next blog, I will show you how to generate an HTML page based on multiple records from a mule event. Till then continue reading the other blogs that I have written and do let me know what is your comment on these.