Created
February 23, 2017 13:24
-
-
Save asm-jaime/9aff97b6e97656a3d053b102bdf35e7f to your computer and use it in GitHub Desktop.
object to url parameter for get query
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
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