krl

URI-encoding a string


I need to send a GET request. One of the parameters has URL query characters in it (e.g., ?, &, and =). How do I URI-encode that in KRL before sending the request?

Here's the pseudocoded idea:

params = "key=value&key=value";
encoded_params = params.urlencode();
request = datasource:service("?data=#{encoded_params}");

Solution

  • See also http://docs.kynetx.com/docs/URI

    escaped = uri:escape("a b c d"); // "a%20b%20c%20d"
    original = uri:unescape(escaped); // "a b c d"