Reputation: 2573
I have two routes /emails
and /eamils/:id
:
var createRouter = function() {
var router = express.Router();
router.route('/emails/:id').get((req, res) => {
console.log('get=>/emails/id');
});
router.route('/emails').get((req, res) => {
console.log('get> /emails');
});
return router;
}
Whenever next request is sent the second handler gets called:
GET http://localhost:4000/rest-api/emails/?id=59
The first one which takes id
parameter never works. How can I fix this?
Upvotes: 0
Views: 341
Reputation:
http://localhost:400/rest-api/emails/59
is correct. You are using params and not queries.
If you want to use queries their usage is like this after ?
sign.
http://localhost:400/rest-api/emails?id=59
Upvotes: 1
Reputation: 30453
You need to use:
http://localhost:4000/rest-api/emails/59
Query parameters don't count.
Upvotes: 1
Reputation: 9056
The correct url should be:
http://localhost:4000/rest-api/emails/59
and not:
http://localhost:4000/rest-api/emails/?id=59
here id is query param.
Upvotes: 5