Share your DataWeave code from GitHub to open directly in the Playground
In case you’re not familiar with this functionality, you can generate shareable links to share your DataWeave examples from a GitHub repository to open directly in the DataWeave Playground. This is especially useful for training purposes.
So now let’s learn how to do this!
Note: For a more detailed explanation + video, you can check out this article. In this post, I’m gonna focus on creating a quick guide that you all can reference in case you forget how to do it!
Step 1: Prepare your GitHub repo
Let’s take this folder as an example.
Inside the folder you want to keep your example, you should at least have a transform.dwl file. This is where you will keep the DataWeave script.
If your example has custom modules, you can add them in the same location where your transform.dwl file is located. You can name them however you like, just make sure the extension is .dwl.
To add one or more inputs, you have to create an inputs folder. Inside it, you can create files for each of the inputs you want to use. For example, payload.json or payload.xml.
In the example I shared, I added an output.xml file. This is not taken into account for the Playground. I just added it to keep a complete example, but it is not needed/used to generate the actual example.
Your folder should look like this:
This previous folder/file structure is assuming you have one input: payload.json, and you have the necessary transform.dwl where you’ll keep the main script.
Once you have your folder structure sorted, make sure this repository is set to public so the Playground can read it.
Let’s now see how to generate the link.
Step 2: Generate the link
These are the parts you will need to generate the link:
Note: The %2F character is used instead of a slash (/) to make it URL-safe.
You only need to replace the repo query parameter with your own repository. For example, alexandramartinez/dataweave-scripts. And the path query parameter with the path to the example folder inside your repo. For example, functions/maskFields.
That’s it! Once you replace both query parameters, you should be able to access your code from the generated link.
Please note that it may take up to 30 minutes to reset the Playground’s cache. In case you don’t see your code right away after making changes to the GitHub repository.
As mentioned at the beginning of the post, you can see a more detailed explanation + video in this article.
Go to ProstDev to keep learning MuleSoft + DataWeave tips!