0
非常に単純なはずのもので私は非常に迷っていますので、ここで助けが必要です。それか私は自分の心を失っています。この作品ノードとエクスプレスでAPI呼び出しから複数のパラメータを取得する方法
:
apiRouter.get('/api/user/:id', secureAPIPages, function(req, res, next){
userModel.findOne({'profileID':req.params.id}, function(err, user) {
if(user){
res.json({
fullname: user.fullname,
about: user.about,
birthday: user.birthday,
email: user.email,
location: user.location
});
} else {
console.log('Result does not exist');
}
});
})
をだから私は電話をかけるとき、私は私が右の問題にジャンプします
express.Routerを()を使用して、私のルートをルーティングしていますので、[OK]を
http://localhost:3000/api/user/123456
"id"変数を取得してreq.paramsに入れます。
さて、問題(これは、上記のものは私のAPIのルーティングが働いていたかどうかをテストするだけである私が仕事をしたいです):なぜそれは私の「ID」を拾っていません
apiRouter.get('/api/user', secureAPIPages, function(req, res, next){
userModel.findOne({'profileID':req.params.id}, function(err, user) {
if(user){
res.json({
fullname: user.fullname,
about: user.about,
birthday: user.birthday,
email: user.email,
location: user.location
});
} else {
console.log('Result does not exist');
}
});
})
このURLをブラウザで実行すると、「名前」変数が表示されます。 http://localhost:3000/api/user?id=123456789&name=Shayan
いつもよろしくお願いいたします。
Shayan
次のように、クエリオブジェクトを使用する必要があります