Summary
When specifying header: { 'content-type': 'application/json' }, the request body is not stringified.
Even when application/json is explicitly set, the body should be parsed and serialized accordingly.
Steps to Reproduce
Run the following code and inspect the request body being sent.
betterFetch("https://example.com", {
headers: {
"content-type": "application/json"
},
body: {
"foo": "bar",
},
method: "POST"
});
Expected Behavior
The request body should be serialized using JSON.stringify before being sent.
Example:
Actual Behavior
The body is sent as [object Object].
Environment
- Library version: 1.1.21
- OS: macOS 15.7.3
- Runtime: Node.js 24.12.0
- Package manager: pnpm 10.25.0
Summary
When specifying
header: { 'content-type': 'application/json' }, the request body is not stringified.Even when
application/jsonis explicitly set, the body should be parsed and serialized accordingly.Steps to Reproduce
Run the following code and inspect the request body being sent.
Expected Behavior
The request body should be serialized using
JSON.stringifybefore being sent.Example:
{ "foo": "bar" }Actual Behavior
The body is sent as
[object Object].Environment