2017-05-07 60 views
0

当我制作端点时,我遇到了风帆问题。相同动词控制器不同端点中的Http航行路线

我在我的路线这个

'get /user': 'UserController.find', 
'get /user/:name': 'UserController.findByName', 

和两个端点在用户控制器

find: function(req,res,next){ 
     res.status(200); 
     res.json("find"); 
}, 
findByName: function(req,res){ 
     res.status(200); 
     res.json("findByName"); 
} 

我用邮差为我的测试,当我提出请求localhost:1337/user/findByName API返回me

findByName(correct)

问题是,当我提出请求localhost:1337/user/find API返回我

findByName太(不正确的:()

为什么?我知道,如果相同的http动词,得到,但我指的是不同的端点。为什么它只返回我findByName ?.

看起来像电话发出请求,但只有它可以看到findByName

对不起,英语不好。谢谢。

回答

0

我想你误解了路由参数的解析。

随着你的路由配置,你应该发送的请求是这样的:

找到

GET localhost:1337/user - 会去寻找在控制器动作。

findByName

GET localhost:1337/user/name - 将转到控制器findByName行动。

看一看docu。还要考虑使用blueprint routes and action,它们已经找到并找到了一个已经实现的。

相关问题