If you want to follow the API-led principles your process and system APIs should not be accessible from outside. These APIs are only for internal usage. On top of them, other APIs are built and the application network grows. Experience APIs should be available for consumers to use. Today I show you how can it…
How to get months and years difference between the two dates?
Some time ago, I was asked to compute the difference between the two dates (Period). Sounds simple, isn’t it? However, I needed this difference presented in days, months, and years. It was not that obvious how to achieve that. Let’ see how I did it. Overview We want to see how long given employee is…
DataWeave Tip #8 – write function
Recently I have been working on a really simple case. When an HTTP server returned an error and not empty body I needed to embed this body into an error structure. Although this is simple case I got a problem with implementing it in Mule 4. In the previous Mule edition it was a little bit simpler. So let’s see what it is all about.
Externalize scripts: a way to reuse scripts
I like the idea of clean easily read XML configuration in my Mule projects. Therefore I externalize DataWeave transformations , SQL quires and other content. In this article I will compare assets that Mule gives as to achieve externalization of such things in Mule 3 and Mule 4.
DataWeave Modules, new way to introduce reusability
It is always desirable to reuse as much code as possible. We can do the same regarding DataWeave transformations and custom functions. In this article, I will describe how to reuse code in the newest DataWeave using modules. For those working with DataWeave 1.0, I will describe how to reuse code with readUrl function. DataWeave…
Remove empty JSON objects from payload using DataWeave function
During transformation to JSON, we often do not want null properties. It is easy to remove them, by just using the skipNullOn attribute. However, for empty objects, it is not that trivial, especially when you have to deal with many such cases within one transformation. In this article, I will show you how you can…
Using filter selector in DataWeave to easily extract data from array
There are times when you need to get one particular element from an array, but not based on the index. This item needs to fulfill some requirements like equality and so on. In order to perform that task filter selector ‘?‘ was introduced. This is applicable for both DataWeave 1 and 2. Filter selector syntax…
How can we call Java code using the DataWeave language?
I have already presented how to call Java code using messages processors with the newest Java Module for Mule 4.x. For earlier mule’s version Entry Point Resolvers were used to invoke custom Java code. However for scenarios when we would like to use custom code in DataWeave, for transformations, another approach is needed. Approach presented in this article will be more concise comparing to using message processors. It was highly extended comparing to possibilities of Mule 3.x version. Mule 3 allowed to invoke static methods. In contract Mule 4 not only permits to call static methods but also instantiate classes and access its instance attributes.
How to convert decimal number into integer using DataWeave
This article is about converting decimal numbers into integer ones. This may seem tricky at first. You may say that we do not need to do anything special and the DataWeave engine will handle it underneath. However, there is a nuance that you should be aware of. In transformation to XML, this may not actually…
How to avoid repetition in DataWeave for conditional checks?
Tip number 1 will be about data existence check. There is often a situation that nearly the same conditions need to be checked in every line. I have seen many transformations that were really long and complex. Reading them was not only difficult but a lot of repeatable conditional checks were made. Here I will…