ProstDev ProstDev
Tutorials Feb 7, 2023 · 3 min read

How to generate shareable link examples from GitHub to open in the DataWeave Playground

Learn how to create shareable links from a GitHub repository to open directly in the online DataWeave Playground.

By Alex Martinez
Thumbnail: How to generate shareable link examples from GitHub to open in the DataWeave Playground

Some months ago, the DataWeave engineering team created this beautiful functionality to be able to open DataWeave examples (including inputs and scripts) directly in the Playground with a single link.

Here’s an example.

In this post, we’re going to learn how to create these shareable links from a GitHub repository to open directly in the online DataWeave Playground.

Let’s use as an example the link I shared at the beginning of the post. This is the complete URL:

https://dataweave.mulesoft.com/learn/playground?projectMethod=GHRepo&repo=alexandramartinez%2Fdataweave-scripts&path=functions%2FmaskFields

Now let’s separate this to make it more readable:

URL partDescription
https://dataweave.mulesoft.com/learn/playgroundThe link should always start with this. This is the URL to open the Playground.
?Marks the start of the query parameters in this URI.
&Marks the concatenation of more query parameters.
projectMethod=GHRepoThis query parameter should always stay the same.
repo=alexandramartinez%2Fdataweave-scriptsThis query parameter indicates where the GitHub repository is located.
This has to be a public repo.
In this case, it’s referencing this repo: github.com/alexandramartinez/dataweave-scripts
path=functions%2FmaskFieldsThis query parameter indicates the path inside the repo where the inputs and scripts are located.
In this case, it’s referencing this folder: alexandramartinez/dataweave-scripts/tree/main/functions/maskFields

You may have noticed that there are some weird characters in the query parameters’ values (%2F). This is just the representation of a slash (/) to make it safe to pass it down in a URL.

To make sure your values for the repo and path query parameters are URL-safe, you can use this tool: urlencoder.org. Simply input your value at the top and click Encode. The encoded value will be returned under the button.

Now that we have a better understanding of how the link is built, let’s now make sure our folder structure inside our repo (the maskFields folder from the previous example) is correctly set.

The folder structure

Since we are only passing the main folder to the Playground, we have to make sure everything is where it’s supposed to be. For that, we have to set the correct folder structure.

The folder structure from the previous maskFieldsfolder example would look like this:

maskFields/
  - inputs/
    - payload.xml
  - transform.dwl

As you can see, this is a simple example where there’s only one payload and only one main script (transform.dwl).

Let’s see a more detailed explanation of what this all means.

Folder/fileDescriptionPlayground section
inputs/This folder should always be named ‘inputs’. This is where you can add several inputs if needed.
Make sure the files have the appropriate extension (.xml, .json, .txt) for the Playground to know which data format it is.
If you’re adding several payloads (for example, one JSON and one XML), make sure they are named differently. You reference these payloads from your scripts using the file name without the extension.
Input Explorer
transform.dwlThis is the main file where your DataWeave script is located. The file name should always be transform.dwl.Script Explorer / Script
Additional modulesIf you want to add custom DataWeave modules to the repo, you should do it at the same level as the transform.dwl file. These modules can have different names but they should all have the .dwl extension.Script Explorer / Script

Once you have everything set up and committed/pushed to your public GitHub repository, you will be able to use the link to share your examples :)

Note

It may take up to 30 minutes for the Playground to be updated after you make any changes to the repository. So, if you do not see your changes being reflected immediately, just wait a bit.

Feel free to contact me for any questions or troubleshooting steps regarding this. I’m happy to help!

-alex

FAQs

Frequently asked questions about this post.

  • What are the parts of a shareable DataWeave Playground link?

    The link always starts with https://dataweave.mulesoft.com/learn/playground, then a ? marks the start of the query parameters and & concatenates more. There are three query parameters: projectMethod=GHRepo, which always stays the same; repo, which points to the public GitHub repository; and path, which points to the folder inside that repo where the inputs and scripts live.

  • Why does the repo value contain %2F instead of a slash?

    The %2F is just the URL-safe representation of a slash (/), so the value can be passed safely inside the URL. To make sure your repo and path values are URL-safe, you can use https://www.urlencoder.org/ — input your value at the top and click Encode, and the encoded value is returned under the button.

  • How should I structure the folder inside my repo?

    Since only the main folder is passed to the Playground, everything has to be in place: an inputs folder (which must always be named 'inputs') holds your payloads, and the main script file must be named transform.dwl at the top level. Any custom DataWeave modules go at the same level as transform.dwl and must have the .dwl extension.

  • How do I add multiple input payloads?

    Add the files inside the inputs folder, making sure each has the appropriate extension (.xml, .json, .txt) so the Playground knows the data format. If you add several payloads, name them differently, and reference each one from your scripts using the file name without the extension.

  • Does my GitHub repository need to be public?

    Yes. The repo query parameter has to point to a public repo, and once everything is set up and committed/pushed to your public GitHub repository you will be able to use the link to share your examples.

  • Why aren't my changes showing up in the Playground right away?

    It may take up to 30 minutes for the Playground to be updated after you make changes to the repository, so if you do not see your changes reflected immediately, just wait a bit.

Search

Loading search…