@pikku/fetch 0.11.1 → 0.12.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.12.0
2
+
3
+ ### New Features
4
+
5
+ - Auto-remove `Content-Type` header for bodyless requests (GET/DELETE)
6
+
1
7
  ## 0.11.0
2
8
 
3
9
  ## 0.11.1
@@ -40,6 +40,10 @@ const corePikkuFetch = (uri, data, options) => __awaiter(void 0, void 0, void 0,
40
40
  uri = `${uri}?${queryString}`;
41
41
  }
42
42
  }
43
- return yield fetch(uri, Object.assign(Object.assign({ method: method.toUpperCase() }, options), { body: body ? JSON.stringify(body) : undefined }));
43
+ const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers);
44
+ if (!body) {
45
+ delete headers['Content-Type'];
46
+ }
47
+ return yield fetch(uri, Object.assign(Object.assign({ method: method.toUpperCase() }, options), { headers, body: body ? JSON.stringify(body) : undefined }));
44
48
  });
45
49
  exports.corePikkuFetch = corePikkuFetch;
@@ -27,9 +27,14 @@ export const corePikkuFetch = async (uri, data, options) => {
27
27
  uri = `${uri}?${queryString}`;
28
28
  }
29
29
  }
30
+ const headers = { ...options?.headers };
31
+ if (!body) {
32
+ delete headers['Content-Type'];
33
+ }
30
34
  return await fetch(uri, {
31
35
  method: method.toUpperCase(),
32
36
  ...options,
37
+ headers,
33
38
  body: body ? JSON.stringify(body) : undefined,
34
39
  });
35
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/fetch",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -33,9 +33,15 @@ export const corePikkuFetch = async (
33
33
  }
34
34
  }
35
35
 
36
+ const headers = { ...options?.headers } as Record<string, string>
37
+ if (!body) {
38
+ delete headers['Content-Type']
39
+ }
40
+
36
41
  return await fetch(uri, {
37
42
  method: method.toUpperCase(),
38
43
  ...options,
44
+ headers,
39
45
  body: body ? JSON.stringify(body) : undefined,
40
46
  })
41
47
  }