Last active
August 15, 2022 18:39
-
-
Save josenaldo/da547f10bfcf6bf9033e1649af2b1bf5 to your computer and use it in GitHub Desktop.
Convert from qs to url
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
var qs = require('qs'); | |
const createBackendApiUrl = (path, params) => { | |
const query = qs.stringify(params, { | |
encodeValuesOnly: true, | |
}) | |
const finalUrl = new URL(`http://localhost:1337/api${path}?${query}`) | |
return finalUrl + '' | |
} | |
const params = { | |
populate: { | |
grupo: '*', | |
}, | |
filters: { | |
slug: { | |
$eq: 'teste', | |
}, | |
}, | |
} | |
const url = createBackendApiUrl('/alianca-zonas', params) | |
console.log(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment