support params in url surrounded by curly braces
This commit is contained in:
@@ -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 = {
|
||||||
|
|||||||
Reference in New Issue
Block a user