%dw 2.0
output application/json
var urlPath = "content folder"
import * from dw::core::URL
---
{ "encodedURL" : compose(["http://examplewebsite.com/", "/page.html"], ["$(urlPath)"]) }
compose
compose(Array<String>, 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
Name | Description |
---|---|
|
A string array that contains the URL parts to interpolate using the strings in the |
|
A string array that contains the strings used to interpolate the |
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
.
Simplified Syntax
You can also call this function using the simplified syntax, which uses backticks (`
) to enclose the string that includes the variable to encode.