node / express REST API application - passing parameters to GET method
Do I need to create two separate methods, one that accepts a parameter and one that doesn't?
I'm guessing you posted this before even trying that?
The answer is yes.
Your route that accepts parameters should look like this:
app.get('/emergency/:id', function (req, res, next) { var id = req.params.id; console.log('The id: ' + id);});
Yes,it is necessary to have two different functions that listen to each type of url.This is because The url
http://localhost/example/abcd will get received in router.get('/example/:username',testFunction1);
whereas
http://localhost/example will be received in router.get('/example',testFunction2);
Refer to the article: http://codewhoop.com/article/Nodejs%20Getting%20parameters%20through%20GET%20methodfor detailed explanation of procedure to fetch paramters through GET method in Nodejs.