I have this in my express
router.put('/admin/profile?:id/actions', (req, res) => {
console.log(req.body.actions)
});
and in postman I do a PUT request
http://localhost:3000/api/admin/58fb442234c93715b435395/actions
with actions as key like
actions:approve
but I get cannot PUT error? I'm expecting 'approve' in my node's console.
Your route might be wrong. As far as I understand the express.js documentation on route paths, as long as your :id
-parameter does not start with either profil
or profile
, your route will not be called.
Remove the profile?
from your path.
try the following in postman as you are sending data in params so the name of action is requires as approve/disapprove
http://localhost:3000/api/admin/58fb442234c93715b435395/approve
if you want to send the key name as well so use query params like
http://localhost:3000/api/admin/58fb442234c93715b435395?action=approve
router.put('/admin/profile?:id/actions',
change your router.put to
router.put('/admin/profile/:id/:actions',
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.