Skip to content

misleading or missing documentation, must JSON.stringify body #23

Closed
@davekaro

Description

@davekaro

I tried to follow the doc example to patch to my rails server:

const response = await patch('localhost:3000/my_endpoint', { body: { name: 'Request.JS' }})

but noticed that [object Object] was being sent as the body. Looking at samples on https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch, I updated my code to stringify the JSON payload first.

const response = await patch('localhost:3000/my_endpoint', { body: JSON.stringify({ name: 'Request.JS' })})

Is this expected or did I miss something? Should the library do this for us? Maybe when the detected content type is application/json (

return 'application/json'
) it should stringify the body?

Metadata

Metadata

Assignees

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