Author: Abhinav Patel
What’s the need for HTML responses in MuleSoft?
Great question! Mule being a middleware tool interacts with multiple applications and services to send and receive responses. These responses can sometimes be required to be structured instead of as a plain string.
Let’s take an example in which you are notifying the purchase details to a customer. The response would be more attractive if the details are properly structured in a tabular format.
Another example would be that your Mule application might require some form of human intervention. These inputs could be taken with the help of a GUI.
With this series, I would like to introduce you all to the new world of services that can be created using MuleSoft tools.
In the first part of this series, we will understand how to render a simple HTML response with the use of “Load static resource”, which helps us load a static resource, such as your home page or a script.

The most important step is to set the path and file name of a resource to be loaded.
In the current walkthrough, we will take step by step measures so as to attain this path value.
Firstly, create a sample HTML file by the name “home.html” within “src/main/resources” folder in your mule project.

Now we will try to read this file at the runtime.
Let’s try to evaluate the current situation. Once the application will be deployed in Mule runtime, the file present under src/main/resources will be directly copied under the application folder as shown below.

Now we need to reach to this path in order to read out HTML file.
For this, we will need to get the values of a few properties like Mule home and the application name. In this walk through, we will retrieve the values and store that in a variable so as to create a path to our working directory. We will make use of Mule and app modules to get the property values as shown below.



To validate our path, I have placed a logger after the set variable component.

Response logged in the console is shown below.

Now we will pass the value of this working directory to the Resource base path in “Http static resource”. I will also keep the default file name as the same. If you want, you can create another file and make it a default file, but make sure that the file is stored in the same working directory.

Our simple application is ready to be deployed. So, let’s run the application and test it.
I am able to get the responses as shown below.

If you’d like, please post your responses as a comment to let me know that your application is up and running!
In the next blog, I will show you how to generate an HTML page based on the values from a Mule event. Till then, be sure to check out the other blogs that I have written and leave your feedback in the comments section!