You need to sign in to do that
Don't have an account?
Hunter Allspaugh
Is there an efficient way to convert a Map<String, String> to a url query?
I'm building a new class to act as an external connector to a project management service, AceProject. The API is purely URL based, so I want to be able to make my http requests dynamically. Trying to build a method to take the Map parameter and return it after it is converted into a string.
Currently, my solution is:
Is there a way to do this without writing the math out? I looked into String.join() but I don't know if I can make that work, since the format needs to be `&key=value`.
Currently, my solution is:
private static String buildHttpUrl(Map<String, String> params){ String url = ''; for (String key : params.keySet()){ if (url.length() != 0){ url += '&'; } url += key + '=' + params.get(key); } return PRIVATE_STR_API + EncodingUtil.urlEncode(url, 'UTF-8'); }
Is there a way to do this without writing the math out? I looked into String.join() but I don't know if I can make that work, since the format needs to be `&key=value`.
I dnt see any issue in this code