i tested rest api using postman and the result
{
"success": true,
"message": "success",
"data": [
{
"id_buku": 9,
"judul_buku": "xxxxxx",
}
]
}
I want "data" : {...} but the result is "data" : [{...}]
i am using express node.js to develop rest api
getDataBukuByID(req,res){
let id = req.params.id;
pool.getConnection(function(err, connection) {
if (err) throw err;
connection.query(
`
SELECT * FROM buku WHERE id_buku = ?;
`
, [id],
function (error, results) {
if(error) throw error;
res.send({
success: true,
message: 'success',
data: results
});
});
connection.release();
})
},
what code should be changed?
response.data[0]