Posts

Showing posts with the label Mulesoft

Handling File Upload in Mule API using Multipart Form Data

Image
     Handling and processing large files via API can sometimes be challenging because the bytes of data need to be encrypted and sent over the network, which may have some bandwidth and security restrictions. However, in my experience it is still possible to send a moderately large file (less than 5 MB) using multipart/form-data POST request in Mule. This is possible because Mule supports streaming of data, which simply means that the whole data is NOT being read and loaded into memory; rather, the data are being read by chunks or buffers of a specific size in an efficient way. The HTTP Listener endpoint is one of those endpoints that support streaming. More technical details here .     File transfers of moderately large file size can be done in Mule. For very large files, I haven't explored this yet, but the most common solution in the past is using the secured FTP transfer. File transfers of very large files via API may be possible but may require a lot more w...

How to Modularize your custom DataWeave 2.0 scripts

Image
     DataWeave is the main expression language in Mule 4, and with the recent version 2.0, it is the sole transformation language in a Mule 4 application. DataWeave is a powerful and rich scripting language, which  supports a variety of useful functions for data manipulations and transformations. It employs a functional programming principle, which means that functions don't have states and side effects. DataWeave functions can also be called recursively (I have done some recursive functions before but will think of a simple concrete example).     If you want to read and study more about DataWeave, and familiarize yourself with the different supported functions, go to  https://docs.mulesoft.com/mule-runtime/4.2/dw-functions     The DataWeave related functions are organized into modules. There are core modules, string modules, binary, cryptography, and a lot more. DataWeave is quite extensible, and I think in future upgrades of Mule we will se...

Welcome to the API World

Image
     This article is about how to jump-start your Mule API development journey. It is assumed that you already know the prerequisites and have the fundamental Mule knowledge. If you're quite new to MuleSoft, API development, or integration in general, I would suggest to go through the official Mule documentation , which would greatly help you get a deep-dive about the platform. If you're entirely new to MuleSoft, I hope that this article will give you a conceptual overview about the platform.      The question I initially had when I was starting Mule development was "Is there a specific, standard, and consistent way of developing Mule APIs?" The answer is either YES or NO.       YES, because it establishes best practices, enables rapid development, and allows you to get past the "boilerplate codes" and be able to move on to the more important implementation of the business logic and requirements. Consistency also means readability in a w...

Global Function that can be used in Mule DataWeave

You can write a Groovy custom function that can be used in Mule DataWeave (Transform Message). To do this, create a file with .mvel extension under src/main/resources, e.g. globalfunction.mvel. If you're familiar with Java, it is quite similar to Groovy, but with some differences such as type declaration is not required in Groovy and a statement doesn't have to be punctuated with a semi-colon as long as you write one statement per line. For example, we have the following Groovy function, which accepts a MongoDB ObjectId and converts it into a string value. This is useful when you just need to get the hexadecimal value and not the object itself, which gets serialized when transforming to JSON. def getObjectIdAsString(objectId) {     return ((org.bson.types.ObjectId) objectId).toString() }    In the Mule configuration file, add the below XML. You don't need to specify the complete path since src/main/resources automatically gets added to the classpat...