We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 11adf38 commit b268a30Copy full SHA for b268a30
src/index.ts
@@ -29,12 +29,15 @@ export default class PineFetch<
29
url: string;
30
body?: AnyObject;
31
} & AnyObject) {
32
- const normalizedBody =
33
- body == null
34
- ? null
35
- : typeof body === 'object'
36
- ? JSON.stringify(body)
37
- : body;
+ let normalizedBody: string | undefined;
+ if (body != null && typeof body === 'object') {
+ // If body is an object then JSON.stringify it and set the matching content-type header
+ options.headers ??= {};
+ options.headers['Content-Type'] = 'application/json';
+ normalizedBody = JSON.stringify(body);
38
+ } else {
39
+ normalizedBody = body;
40
+ }
41
42
const response = await fetch(url, {
43
...options,
0 commit comments