When I send the following request from my Chrome devtools
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: {
title: 'foo',
body: 'bar',
userId: 1,
},
headers: {
'Content-type': 'application/javascript',
},
})
.then((response) => response.json())
.then((json) => console.log(json));
This is the output I get:
{id: 101}
Which is not what I expect, in fact I expect
{title: 'foo', body: 'bar', userId: 1, id: 101}
that I get when I use Content-Type of 'aplication/json' like in the code below:
fetch('https://jsonplaceholder.typicode.com/posts/1', {
method: 'POST',
body: JSON.stringify({
title: 'foo',
body: 'bar',
userId: 1,
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
})
.then((response) => response.json())
.then((json) => console.log(json));