Contact Free trial Login

compose

compose(Array<String>, Array<String>): String

Uses a custom interpolator to replace URL components with a encodeURIComponent result.

Parameters

Name Description

parts

A string array that provides the part of the URL to encode.

Example

This example passes in text to encode using $(myText), where myText is a variable defined in the header. Notice that the spaces in the input are encoded in the output URL as %20. Also notice that the entire input to the compose function is surrounded by backticks.

Source

%dw 2.0
import * from dw::core::URL
var myText = " text to encode "
output application/json
---
{ "composition" : compose `http://asd/$(myText)/text` }

Output

{ "composition": "http://asd/%20text%20to%20encode%20/text" }