Created
May 19, 2020 16:54
-
-
Save ccondry/1165c032d9b375c7d5c3f21ba282452b to your computer and use it in GitHub Desktop.
add URL query parameters for fetch / node-fetch
This file contains 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
function addUrlQueryParams (endpoint, params) { | |
let url = new URL(endpoint) | |
if (params) { | |
// append URL query paramenters | |
Object.keys(params).forEach(key => { | |
url.searchParams.append(key, params[key]) | |
}) | |
} | |
return url | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment