Skip to content

Instantly share code, notes, and snippets.

@asm-jaime
Created February 23, 2017 13:24
Show Gist options
  • Save asm-jaime/9aff97b6e97656a3d053b102bdf35e7f to your computer and use it in GitHub Desktop.
Save asm-jaime/9aff97b6e97656a3d053b102bdf35e7f to your computer and use it in GitHub Desktop.
object to url parameter for get query
function obj_to_param(obj) {
return Object.keys(obj).map(function(key) {
return key + '=' + obj[key];
}).join('&');
}
function somef(obj) {
fetch(`${URL}/api/get/some?${obj_to_param(obj)}`)
.then((res) => res.json())
.then((json) => console.log('some: ', json.body))
.catch(error => console.log('some error: ', error));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment