Reputation: 129
When I send an object as a parameter of my post or get request express doesn't seem to receive it
I have tried get and post requests both on the front end and on the server. All the dependencies are working fine (body-parser, etc.)
front end:
axios.get('http://localhost:4000/videoComments/comment', {pauseTime: 10})
or
axios.get('http://localhost:4000/videoComments/comment', {data:{pauseTime: 10}})
back-end:
videoCommentsRoutes.route('/comment').get(function (req, res) {
console.log(req.body);
req.body is an empty object. req.data, req.params are all undefined
Upvotes: 1
Views: 63
Reputation: 3062
Back-End should be like
videoCommentsRoutes.route('/comment/:pauseTime').get(function (req, res) {
console.log(req.params.pauseTime);
})
or
videoCommentsRoutes.route('/comment').get(function (req, res) {
console.log(req.query.pauseTime);
})
Front-end Call like
axios.get('http://localhost:4000/videoComments/comment', {params:{pauseTime: 10}})
Upvotes: 0