@bryanochoa/custom-fetch-api 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +9 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -37,33 +37,38 @@ var CustomFetchAPI = class {
|
|
|
37
37
|
}
|
|
38
38
|
async get(url, searchParams) {
|
|
39
39
|
this.verifyTokenWereSet();
|
|
40
|
+
this.optionRequest.method = "GET";
|
|
41
|
+
if (this.optionRequest.body) this.optionRequest.body = void 0;
|
|
42
|
+
if (this.headers.has("Content-Type")) this.headers.delete("Content-Type");
|
|
40
43
|
const finalUrl = this.setParams(url, { searchParams });
|
|
41
44
|
return await (await fetch(finalUrl, this.optionRequest)).json();
|
|
42
45
|
}
|
|
43
|
-
async post(url, { searchParams, body, contentType }) {
|
|
46
|
+
async post(url, { searchParams, body, contentType = "application/json" }) {
|
|
44
47
|
this.verifyTokenWereSet();
|
|
45
48
|
this.optionRequest.method = "POST";
|
|
46
49
|
this.setBody(body, contentType);
|
|
47
|
-
const finalUrl = this.setParams(url, searchParams);
|
|
50
|
+
const finalUrl = this.setParams(url, { searchParams });
|
|
48
51
|
return await (await fetch(finalUrl, this.optionRequest)).json();
|
|
49
52
|
}
|
|
50
53
|
async put(url, { searchParams, body, contentType }) {
|
|
51
54
|
this.verifyTokenWereSet();
|
|
52
55
|
this.optionRequest.method = "PUT";
|
|
53
56
|
this.setBody(body, contentType);
|
|
54
|
-
const finalUrl = this.setParams(url, searchParams);
|
|
57
|
+
const finalUrl = this.setParams(url, { searchParams });
|
|
55
58
|
return await (await fetch(finalUrl, this.optionRequest)).json();
|
|
56
59
|
}
|
|
57
60
|
async patch(url, { searchParams, body, contentType }) {
|
|
58
61
|
this.verifyTokenWereSet();
|
|
59
62
|
this.optionRequest.method = "PATCH";
|
|
60
63
|
this.setBody(body, contentType);
|
|
61
|
-
const finalUrl = this.setParams(url, searchParams);
|
|
64
|
+
const finalUrl = this.setParams(url, { searchParams });
|
|
62
65
|
return await (await fetch(finalUrl, this.optionRequest)).json();
|
|
63
66
|
}
|
|
64
67
|
async delete(url) {
|
|
65
68
|
this.verifyTokenWereSet();
|
|
66
69
|
this.optionRequest.method = "DELETE";
|
|
70
|
+
if (this.optionRequest.body) this.optionRequest.body = void 0;
|
|
71
|
+
if (this.headers.has("Content-Type")) this.headers.delete("Content-Type");
|
|
67
72
|
const uri = this.baseUrl ? `${this.baseUrl}${url}` : url;
|
|
68
73
|
return await (await fetch(uri, this.optionRequest)).json();
|
|
69
74
|
}
|