Reputation: 514
I'm having an issue with my Rest service. The two routes I'm trying to have are:
router.get('/stocks/:ticker', function(req, res){
and
router.get('/stocks/watchlist/', function(req, res){
when I call
http://localhost:8000/stocks/watchlist
my API believes 'watchlist' is the ticker symbol and goes to the incorrect route. I'm sure I'm missing something fundamental here.
Upvotes: 1
Views: 37
Reputation: 707218
Move the watchlist route in front of the other one.
That way it will get matched before the more open ended one gets to see the request at all. Routes are compared in the order they were defined and the first one to match gets it first. If it doesn't call next()
to continue routing, then it will be the only one to see the route.
Upvotes: 2