---
schema_version: "1"
id: c704c740ad121d0842573e54a47fe6a0316b290496cfdee12eff18678c06d0cb
title: Mock Data Using a DataWeave Library
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/mock-data-using-dw-library.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/mock-data-using-dw-library
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 6da3b63ab9e72a6505ed91235c195f92b651b2e7ae3ee4219a21937fd45e80cd
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Mock Data Using a DataWeave Library

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The following tutorial shows you how to develop an integration, import the
[Mock Data Generators Library](https://anypoint.mulesoft.com/exchange/68ef9520-24e9-4cf2-b2f5-620025690913/data-weave-mock-data-generators-library/minor/1.0/)
from Exchange, and use the custom library to return a random value from the library.

## Before You Begin

Before getting started, ensure you:

- Set up your MuleSoft environment.  
  See [Getting Started with Anypoint Code Builder](https://docs.mulesoft.com/anypoint-code-builder/start-acb) for more information.

## Create a Mule Application

1.  In Anypoint Code Builder, open the Command Palette by pressing Ctrl+shift+p (Mac) or Cmd+shift+p
    (Windows), and type `MuleSoft: Develop an Integration`.

2.  Select the command.

3.  Configure your integration using the following values:

    ![Develop an Integration form, with Empty Project selected](/mulesoft/current/en-us/anypoint-code-builder/_images/int-create-integration-scratch.png)

    1.  Under **Project Name**, provide the name \*mock-dw-library.

    2.  Under **Project Location**, click **Browse**, and then select your home directory.

    3.  Under **Create**, select **Empty Project**.

    4.  Select a **Mule runtime** and **Java** version.

        You can select from locally available Mule runtime and Java versions. The dropdown shows
        only the Mule runtime versions that are installed on your local disk, including bundled Mule
        runtime versions that are available immediately after installation. Anypoint Code Builder
        saves your version settings to the project’s `mule-artifact.json` file. Bundled Mule runtime
        versions enable instant project opening and design. To install additional Mule runtime
        versions, use the `MuleSoft: Install Runtime` command. For information about version support
        and automated Mule patch updates, see
        [Mule and Java version support](https://docs.mulesoft.com/anypoint-code-builder/acb-release-notes#versions-mule-jdk). To set default Mule
        runtime and Java versions for the projects you create, see
        [Version Settings for Mule, Java, and Connectors](https://docs.mulesoft.com/anypoint-code-builder/int-versions).

4.  Click **Create Project**.

## Create a Flow

Start by configuring a flow with an HTTP listener that exposes a root path (`/`):

1.  Between the `<mule>` and `</mule>` elements, create an HTTP Listener global configuration:

    ```XML
    <http:listener-config name="HTTP_Listener_config" >
      <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    ```

2.  After the `</http:listener-config>` element, add a flow and an HTTP Listener element:

    ```XML
    <flow name="receive-request" doc:name="Flow" >
      <http:listener path="/" config-ref="HTTP_Listener_config" doc:name="Listener" doc:id="bbzemf" />
    </flow>
    ```

## Import the DataWeave Library

1.  Open the Command Palette by pressing Ctrl+Shift+p (Windows) or Cmd+Shift+p (Mac), and provide
    the following command:

    ```command
    MuleSoft: Import Asset from Exchange
    ```

2.  Select **DataWeave Library**.

3.  Start typing _DataWeave_, and press Return to list assets that match your search.

4.  Select **DataWeave Mock Data Generators Library**.

5.  Select version **1.0.0**.

Anypoint Code Builder displays a message indicating that the dependency was successfully added.

## Use the DataWeave Library

1.  After the `<http:listener>` element, add a new line and create a Set Payload processor:

    ```XML
    <flow name="receive-request" doc:name="Flow" >
      <http:listener path="/" config-ref="HTTP_Listener_config" doc:name="Listener" doc:id="bbzemf" />
      <set-payload value="#[]" doc:name="Set Payload" doc:id="ee6848" />
    </flow>
    ```

2.  Add the following DataWeave script inside the `value` element of the `set-payload` element:

    ```dataweave
    %dw 2.0
    output application/json
    import * from mocks::DataGenerators
    ---

    mocks::DataGenerators::randomCity()
    ```

Review your XML code:

```XML
<flow name="receive-request" doc:name="Flow" >
  <http:listener path="/" config-ref="HTTP_Listener_config" doc:name="Listener" doc:id="bbzemf" />
  <set-payload
    doc:name="Set Payload"
    value="#[%dw 2.0 output application/json import * from mocks::DataGenerators --- mocks::DataGenerators::randomCity()]"
    />
</flow>
```

## Import the HTTP Connector Library

1.  Open the Command Palette by pressing Ctrl+Shift+p (Windows) or Cmd+Shift+p (Mac), and provide
    the following command:

    ```command
    MuleSoft: Import Asset from Exchange
    ```

2.  Select **Connector**.

3.  Start typing _HTTP_, and press Return to list assets that match your search.

4.  Select **HTTP Connector - Mule 4**.

5.  Select the latest version.

Anypoint Code Builder displays a message indicating that the dependency was successfully added.

## Deploy the Application

1.  Open the Command Palette by pressing Ctrl+Shift+p (Windows) or Cmd+Shift+p (Mac), and provide
    the following command:

    ```command
    MuleSoft: Deploy to CloudHub
    ```

2.  Anypoint Code Builder prompts that a deployment configuration file has been created and opens it
    for you to review:

    ```json
    {
      "runtime": "4.4.0", (1)
      "workerSize": 0.1,
      "applicationName": "mock-dw-library", (2)
      "workers": 1,
      "autoStart": true
    }
    ```

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>The <code>runtime</code> version is the Mule runtime version you select when creating the integration.<div><p>For information about version support and automated Mule patch updates, see <a href="https://docs.mulesoft.com/anypoint-code-builder/acb-release-notes#versions-mule-jdk">Mule and Java version support</a>.</p></div></td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>The <code>applicationName</code> property defines the part of the URL that you use to access your application on CloudHub.<div><p>The name must be unique across all applications deployed to CloudHub.</p></div></td></tr></tbody></table>

3.  After reviewing the deployment configuration, select **Deploy** to deploy the application to
    CloudHub.

4.  Select your preferred environment.

    Anypoint Code Builder packages the application and deploys it to CloudHub.

5.  After deployment completes, select **Open in Runtime Manager**.

6.  Select your application from the application list.  
    The domain name of the application varies, but it follows a similar structure such as:
    `mock-dw-library.eu-s1.cloudhub.io`.

7.  Open your preferred REST client and make a GET request to the domain name as displayed in
    **Runtime Manager**.

8.  Your application now returns a random city every time you reach the endpoint.
