Zoho Deluge: Convert Map to URL Parameters

What?
A quick article on converting a Map (associative array with keys and values) into a URL string to pass as URL parameters.

How?
Let's first define a map:
m_Payload = Map();
m_Payload.put("client_id","my-unique-client-id");
m_Payload.put("redirect_uri","https://www.joellipman.com");
m_Payload.put("response_type","code");
m_Payload.put("scope","my_api_scopes");
m_Payload.put("prompt","login");
Great! What follows is the code I'm using to convert this:
v_Endpoint = "https://api.joellipman.com/myapi";
l_UrlParams = List();
for each v_Key in m_Payload.keys()
{
	l_UrlParams.add(v_Key.toString() + "=" + m_Payload.get(v_Key));
}
info v_Endpoint + "?" + l_UrlParams.toString("&");

// yields https://api.joellipman.com/myapi?client_id=my-unique-client-id&redirect_uri=https://www.joellipman.com&response_type=code&scope=my_api_scopes&prompt=login

In Reverse
To have the reverse effect of converting a URL into a map, I'm using the following:
v_ReturnedUrl = "https://api.joellipman.com/myapi?isAuthSuccessful=true&code=my_own_code&expires_in=299";
l_ReturnedUrlParts = v_ReturnedUrl.subString(v_ReturnedUrl.indexOf("?")+1).toList("&");
m_UrlParams = Map();
for each  r_Part in l_ReturnedUrlParts
{
	if(r_Part.contains("="))
	{
		l_ParamParts = r_Part.toList("=");
		m_UrlParams.put(l_ParamParts.get(0), l_ParamParts.get(1));
	}
}

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.