I am sending a simple fetch() to my server as follows:
eo.put = function (state) {
console.log('PUT:state', state);
let _id = encodeURIComponent(state._id);
const options = {
headers: {'Content-Type': 'application/json'},
method: 'PUT',
body: JSON.stringify(state)
};
fetch("/articles/put/" + _id, options )
.then((response) => {
console.log('RESPONSE', response);
// you need to update the DOM here
})
.catch((error) => {
console.error("DEBUG: fetch/PUT error", error);
});
}
and I can verify that state is populated with the console.log().
However; on the server side req.body is not populated and shows undefined.
// .. snip
app.use('/articles', routes.articles);
// .. snip
// UPDATE OPERATIONS
router.route('/put/:_id').put((req, res) => {
const _id = req.params._id;
const obj = req.body;
/*
**
** req.body is empty
**
*/
debug && console.log('DEBUG: route: /articles/put : req.body', req.body);
DBM.updateArticle(_id, obj).then(() => {
}).catch((err)=>{
res.status(500).send("DEBUG: database internal error", err);
});
res.end();
});