Over a million developers have joined DZone.

MuleSoft Dataweave Language: Reading Properties From Files Dynamically

DZone's Guide to

MuleSoft Dataweave Language: Reading Properties From Files Dynamically

This quick tutorial will show you how to read a properties file dynamically in Mule, using MuleSoft's Dataweave language.

· Integration Zone ·
Free Resource

Are your API program basics covered? Read the 5 Pillars of Full Lifecycle API Management eBook

In this tutorial, we will see how we can use MuleSoft's Dataweave language to read a properties file dynamically.

As a first step, let's create a new Mule project using Anypoint Studio. After creating the project, let's define our code list as follows:

GB=United Kingdom
USA=United State of America

We will name it 'codelist.properties.' Place it under your Mule project 'src/main/resouces' folder.

Image title

Next, let's add the properties file in our global configuration. We will add a new property place holder. For this step, go to Global Elements -> Create -> Property Place.

Image title

Let's create a flow with an HTTP inbound connector.

Image title

We have set the path to be '/country' and Allowed Methods to be 'GET' only. For HTTP Connector configuration, we have used the following settings:

Image title

As a next step, let us assume we will get a query parameter named 'code' in our request. We will set that parameter in a local variable named 'countryCode.'

Image title

In the final step, lets add a Transform Message component and call the dataweave function 'p.'

Image title

We can test the service after deploying the application in Anypoint Studio. You can use a browser or Postman to hit the service.

For request, try any one of the following URL's.





The response will come back as follows (based on the code you've sent across as the query parameter):

  "country": "United Kingdom"

I hope this article helps you understand how to read properties file dynamically using the Mulesoft Dataweave language.

Establish API creation, publishing and discovery as a master practice with the API Management Playbook.

mulesoft ,dataweave ,anypoint studio ,integration ,mule ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}