2017-05-07 24 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,它們已經找到並找到了一個已經實現的。

相關問題