Created
July 28, 2022 08:44
-
-
Save dehidehidehi/26145b5d43820eaf758d87f8c318560a to your computer and use it in GitHub Desktop.
Builds a basic url: path params and query params from Maps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static URI buildUri(String baseUrl, LinkedHashMap<String, String> pathParams, LinkedHashMap<String, String> queryParams) { | |
| StringBuilder sb = new StringBuilder(baseUrl); | |
| if (Objects.nonNull(pathParams)) | |
| sb.append("/").append(String.join("/", pathParams.values())); | |
| if (Objects.nonNull(queryParams)) { | |
| List<String> keyValueStrings = queryParams.entrySet().stream().map( | |
| e -> e.getKey() + "=" + e.getValue()).collect(Collectors.toUnmodifiableList()); | |
| sb.append("?").append(String.join("&", keyValueStrings)); | |
| } | |
| return URI.create(sb.toString()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment