Reputation: 251
In react js how to send axios GET method request with parameters to Node js and in Node js how to get these parameters.
I tried below, but not working.
React js sending
(async () => {
const totalDonations = await axios.get(
"http://localhost:3000/api/userdashboard/UserDonorList", {
params: {
assignEvent: props.match.params.event,
userEmail: props.match.params.user
}
}
);
console.log(totalDonations.data)
setDonationDetailList(list => [...list,...totalDonations])
})();
Node js reading
userRouter.get('/api/userdashboard/UserDonorList', userAuth, async (req, res) => {
try {
if(!req.user){
} else {
const donationInfo = await DonationCreate.find({ userEmail: req.body.userEmail, assignEvent: req.body.assignEvent })
console.log('donationInfo: ', donationInfo)
res.status(201).send(donationInfo)
}
}
catch (e) {
console.log('e: ', e)
const errors = errorhandle(e)
res.status(400).send(errors)
}
});
Upvotes: 0
Views: 1241
Reputation: 499
Use req.query
to get access to all the parameter in form of Object in the req object.
Example : req.query.assignEvent
Upvotes: 1