Last active
May 13, 2019 08:37
-
-
Save SeedyROM/1d0458a8333af77c3d177fd451e991c6 to your computer and use it in GitHub Desktop.
Functional helper to build query parameters for GET requests.
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
const buildQueryParams = (params) => ( | |
Object | |
.keys(params) | |
.reduce((q, k) => q + `${k}=${params[k]}&`, '?') | |
.slice(0, -1) | |
); | |
// Usage: | |
const queryParams = buildQueryParams({ | |
hello: 'world', | |
query: true, | |
}); | |
console.log(queryParams); // ?hello=world&query=true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment