rest-api-kit
Advanced tools
Comparing version 0.0.42 to 0.0.43
@@ -39,3 +39,3 @@ type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; | ||
headers: HeadersInit; | ||
bodyAsQueryParams: boolean; | ||
bodyAsParams: boolean; | ||
} | ||
@@ -42,0 +42,0 @@ interface StoreHookReturnType<R, T> { |
@@ -99,6 +99,14 @@ "use strict"; | ||
if (url.includes("/:")) { | ||
const queryParams = []; | ||
for (const [key, value] of Object.entries(body)) { | ||
const regex = new RegExp(`/:${key}`, "g"); | ||
url = url.replace(regex, `/${value}`); | ||
if (regex.test(url)) { | ||
url = url.replace(regex, `/${value}`); | ||
} else { | ||
queryParams.push(`${key}=${value}`); | ||
} | ||
} | ||
if (queryParams.length > 0) { | ||
url += `?${queryParams.join("&")}`; | ||
} | ||
return url; | ||
@@ -320,3 +328,3 @@ } | ||
url = getBaseUrl(url, options?.baseUrl); | ||
const formattedUrl = params.method === "GET" || params.bodyAsQueryParams ? concatenateParamsWithUrl(url, body) : !!body && !!urlParams ? concatenateParamsWithUrl(url, urlParams) : url; | ||
const formattedUrl = params.method === "GET" || params.bodyAsParams ? concatenateParamsWithUrl(url, body) : !!body && !!urlParams ? concatenateParamsWithUrl(url, urlParams) : url; | ||
load(dispatch, formattedUrl, { ...params, headers }, body); | ||
@@ -350,3 +358,3 @@ let storeIdentifier = `${options.baseUrl || ""}&${params.endpointName}`; | ||
url: formattedUrl, | ||
body: params.bodyAsQueryParams ? {} : body, | ||
body: params.bodyAsParams ? {} : body, | ||
method: params.method | ||
@@ -407,3 +415,3 @@ }, | ||
successCondition: () => true, | ||
bodyAsQueryParams: false, | ||
bodyAsParams: false, | ||
headers: {} | ||
@@ -410,0 +418,0 @@ }; |
{ | ||
"name": "rest-api-kit", | ||
"version": "0.0.42", | ||
"version": "0.0.43", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.mjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
34768
983