---
schema_version: "1"
id: 615edccf5a5ec53bba6f2cb0d1504d1121a500c6a58b014bbd52dce0defa4a27
title: compose
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-url-functions-compose.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-url-functions-compose
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 70715f455897dd71dec5c487f8266a41456ef7eb4cc32fc22c0826989cf5ce95
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# compose

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

## compose(parts: Array<String>, interpolation: Array<String>): String

Uses a custom string interpolator to replace URL components with a `encodeURIComponent` result. You
can call this function using the standard call, or a simplified version.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>baseStringArray</code></p></td><td><p>A string array that contains the URL parts to interpolate using the strings in the <code>interpolationStringArray</code> parameter.</p></td></tr><tr><td><p><code>interpolationStringArray</code></p></td><td><p>A string array that contains the strings used to interpolate the <code>baseStringArray</code>.</p></td></tr></tbody></table>

### Example

The following example uses the compose function to form an encoded URL, the first parameter is an
array of two strings that are part of the URL and the second parameter is the `urlPath` variable
that is used to interpolate the strings in the first parameter. Notice that the spaces in the input
are encoded in the output URL as `%20`.

#### Source

```DataWeave
%dw 2.0
output application/json
var urlPath = "content folder"
import * from dw::core::URL
---
 { "encodedURL" : compose(["http://examplewebsite.com/", "/page.html"], ["$(urlPath)"]) }
```

#### Output

```JSON
{ "encodedURL" : "http://examplewebsite.com/content%20folder/page.html" }
```

### Example

You can also call this function using the simplified syntax, which uses backticks (`` ` ``) to
enclose the string that includes the variable to encode. This example shows how to use the
simplified syntax to obtain the same result as in the previous example.

#### Source

```DataWeave
%dw 2.0
output application/json
var urlPath = "content folder"
import * from dw::core::URL
---
{ "encodedURL" : compose `http://examplewebsite.com/$(urlPath)/page.html`}
```

#### Output

```JSON
{ "encodedURL" : "http://examplewebsite.com/content%20folder/page.html" }
```
