support params in url surrounded by curly braces

This commit is contained in:
2023-02-27 08:43:44 +10:00
parent 35f5b382fa
commit c9e2350155

View File

@@ -37,12 +37,21 @@ export const api = {
let url = this.baseUrl + options.url; let url = this.baseUrl + options.url;
if (options.params) { if (options.params) {
url = let params = "";
url +
"?" + for (const [key, value] of Object.entries(options.params)) {
Object.keys(options.params) const placeholder = `{${key}}`;
.map((key) => key + "=" + options.params[key]) if (url.includes(placeholder)) {
.join("&"); url = url.replace(placeholder, value);
} else {
params += `&${key}=${value}`;
}
}
url = url.replace(/{(.*?)}/g, "$1");
if (params.length > 0) {
url += (url.includes("?") ? "" : "?") + params.substring(1);
}
} }
options.headers = { options.headers = {