I cannot get the body correct on the server. If I use content type of json, I get an empty body, if I use urlencoded I get the body but not parsed. Looks like this { { "title": "New Title" }: '' } I would expect to just access a property on the body like so, req.body.title. I'm using latest version of node and express.
Client
function editMovies() {
//var putMethod = { method: 'PUT', headers: { "Content-Type": "content-type: application/json" } };
var putMethod = { method: 'PUT', headers: { "Content-Type": "application/x-www-form-urlencoded" } };
putMethod.body = JSON.stringify({ "title": "New Title" });
fetch("/api/movies/2", putMethod).then(function (response) {});
}
Server
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.put('/api/movies/:id', function (req, res) {
var id = req.params.id;
console.log('put called with:' + req.body.title);
});