Functions - encoding

decodeBase64Url
Decodes the Base64 URL encoded string into a byte array.
decodeUriComponent
Decodes the given URI component into a string using the provided charset.
encodeBase64Url
Returns the Base64 URL encoded string value of the given byte array.
encodeUriComponent
Encodes the given URI component into a string using the provided charset.

decodeBase64Url

(string input)

returns byte[] | Error
Decodes the Base64 URL encoded string into a byte array.
 byte[]|encoding:Error urlDecodedValue = encoding:decodeBase64Url("SGVsbMO2IFfDtnJsZEBCYWxsZXJpbmE");

Parameters

  • input string
  • Value to be decoded

  • Return Type

    (byte[] | Error)
  • Decoded output or else a mime:Error if the input is not a valid Base64 URL encoded value

decodeUriComponent

(string uriComponent, string charset)

returns string | Error
Decodes the given URI component into a string using the provided charset.
 string encodedUrl = "http://www.domain.com/?param1=http%3A%2F%2Fxyz.com%2F%3Fa%3D12%26b%3D55¶m2=99";
 string|encoding:Error decodedUriComponent = encoding:decodeUriComponent(encodedUrl, "UTF-8");

Parameters

  • uriComponent string
  • URI component to be decoded

  • charset string
  • Character set to be used in decoding the URI

  • Return Type

    (string | Error)
  • The string value of the decoded URI component or an Error that occurred during decoding

encodeBase64Url

(byte[] input)

returns string
Returns the Base64 URL encoded string value of the given byte array.
 string query = "Hellö Wörld@Ballerina";
 string urlEncodedValue = encoding:encodeBase64Url(query.toBytes());

Parameters

  • input byte[]
  • Byte array to be encoded

  • Return Type

    (string)
  • Encoded output

encodeUriComponent

(string uriComponent, string charset)

returns string | Error
Encodes the given URI component into a string using the provided charset.
 string urlValue = "param1=http://xyz.com/?a=12&b=55¶m2=99";
 string|encoding:Error encodedUriComponent = encoding:encodeUriComponent(urlValue, "UTF-8");

Parameters

  • uriComponent string
  • URI component to be encoded

  • charset string
  • Character set to be used in encoding the URI

  • Return Type

    (string | Error)
  • The string value of the encoded URI component or an Error that occurred during encoding