Search code examples
javascriptnode.jsrestify

What is the difference between these 2 HTTP Get definitions?


I am using Node.js Restify.

What is the difference between these 2 ways of defining HTTP Get requests on the server side? How will it affect the client URL calling the GET APIs and retrieving the URL parameters?

First one.

server.get('/echo', function (req, res, next) 
{
}

Second one.

server.get('/echo/:message', function (req, res, next)
{
}

Solution

  • The first is a simple route that accepts requests using the "/echo" or "/echo/" path.

    The second has a named parameter. Meaning you can access the passed value from request using "/echo/xxx" path via

    req.params.message