sac Dahal sac Dahal - 1 month ago 5
Javascript Question

Not able to send put request with postman

what I am sending is

http://localhost:3000/accounts?user_id=62139fbf-ce6a-4827-8fe8-f1c3197bff82
// params
user_id 62139fbf-ce6a-4827-8fe8-f1c3197bff82


My Api in node Js inside account.js is

router.route('/:user_id').put(function(req, res) {
console.log("hello")


It works when I change the route to the following( i.e I remove the params user_id and also from the postman.

router.route('/').put(function(req, res) {
console.log("efwe")


So the problem is with sending params any help.

Answer

I believe your URL should be like -

http://localhost:3000/accounts/62139fbf-ce6a-4827-8fe8-f1c3197bff82

for route - router.route('/accounts/:user_id').

For query parameters you need to do something like this - http://localhost:3000/accounts?user_id=62139fbf-ce6a-4827-8fe8-f1c3197bff82

router.route("/accounts",function(req,res){
    var id = req.query.user_id; // Check syntax for framework you are using 
});
Comments