-3

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)
{
}
guagay_wk
  • 26,337
  • 54
  • 186
  • 295
  • 1
    The first one gets no parameter, the second one has a `message` parameter ? – Matteo Tassinari Nov 05 '15 at 07:53
  • What is the actual question? The parameter? – dude Nov 05 '15 at 07:54
  • 1
    If only there were something one could refer to, some kind of [documentation](http://mcavage.me/node-restify/#routing) or something... – T.J. Crowder Nov 05 '15 at 07:55
  • THe question is ... How will it affect the client calling the GET APIs? What URL should the client be using? – guagay_wk Nov 05 '15 at 07:55
  • the extra `:message` to url seems to be `socket path`. I am not sure though. – Mr_Green Nov 05 '15 at 07:56
  • May I ask why the 2 negative votes? Please explain so that I can ask better questions in future. Thanks. – guagay_wk Nov 05 '15 at 07:56
  • `What URL should the client be using? ` - the one appropriate for the situation – Jaromanda X Nov 05 '15 at 07:57
  • 1
    @user3293156 don't care about the downvotes. it is just 2 users out of 21 users (21 views). – Mr_Green Nov 05 '15 at 08:00
  • 3
    The question got downvoted for the reasons the downvote button shows you when you hover it: It's unclear, and it demonstrates no research effort. If you read the Restify documentation and look at its examples, it's quite clear what the `:message` means in the route definition and how that would affect what the client would use when calling the endpoint. So if, having read the documentation and followed the examples, you have a specific question about how `:message` is determined or specified or some such, ask that question, with details about what you don't understand. – T.J. Crowder Nov 05 '15 at 08:01
  • 1
    More: [*How do I ask a good question?*](/help/how-to-ask) – T.J. Crowder Nov 05 '15 at 08:02
  • T.J. Crowder, thanks. That is a good explanation. Upvoted your comment. – guagay_wk Nov 05 '15 at 08:02

1 Answers1

1

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
Christopher
  • 412
  • 3
  • 11