无法向邮递员发送put请求

时间:2016-11-04 09:13:15

标签: javascript node.js

我发送的是

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

在account.js中的节点Js中我的Api是

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

当我将路线更改为以下路线时,它会起作用(即我删除了params user_id以及邮递员。

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

所以问题在于向params发送任何帮助。

1 个答案:

答案 0 :(得分:2)

我相信您的网址应该像 -

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

路线

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

对于查询参数,您需要执行以下操作 - 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 
});
相关问题