server
app.post('/articles', (req, res) => {
let query = `SELECT * FROM articles where title = ?`; // query database to get all the players
// execute query
db.query(query, {title: req.body.title} (err, result) => {
if (err) {
res.send({
err: err,
status: 500
});
return;
}
res.send({
result,
status: 200
})
});
});
client
fetch('/articles', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify( { title: 'Articles-1' /* selected menu item */ } )
})
.then(data => data.json())
.then(console.log)
.catch(console.error)