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

# 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" }
```
