Sunday 25 June 2017

[?] Express Routes: How can I extend route URLs?

I am learning about creating REST API's using Node.js and Express.js. I come from a C# background.Typically routes are structured like this:*GET* server.get('/info/:param_string', function(req, res, next) { res.send(201, "hello " + req.query.param_string); return next(); }); Where the URL is: localhost:3000/info/:param_stringI wish to achieve this: localhost:3000/info/ **getInfo** /:param_stringHow can I add the 'getInfo' text into the URL?When I try and add the 'getInfo' text in the code above, I receive an error such as: Cannot GET /info/getInfo/:query_stringUsing express, is there a way to achieve custom URL endpoints like that?ThanksExtra bonus points if you can also tell me how to use this same functionality using Restify

Submitted June 26, 2017 at 06:13AM by Champion01

No comments:

Post a Comment