Skip to content

Instantly share code, notes, and snippets.

@SeedyROM
Last active May 13, 2019 08:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeedyROM/1d0458a8333af77c3d177fd451e991c6 to your computer and use it in GitHub Desktop.
Save SeedyROM/1d0458a8333af77c3d177fd451e991c6 to your computer and use it in GitHub Desktop.
Functional helper to build query parameters for GET requests.
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