Skip to content

Request body is not JSON-stringified when Content-Type: application/json is specified #76

@ryota-iso

Description

@ryota-iso

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:

{ "foo": "bar" }

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions