Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  42] [ 5]  / answers: 1 / hits: 57861  / 12 Years ago, tue, august 28, 2012, 12:00:00

I am quite new to Javascript and node.js and I'm trying to create a REST API, and the urls will be of the form.




  1. /user/{userId}/docs



I am trying to get the value of {userId}, which in the case of /user/5/docs will be 5.



I could try to pass this as a request parameter(in the querystring or in the body, depending on the GET or POST method), but the url looks more intuitive when it is formed this will. Plus there are many more urls which are like these.



I am wondering if there are any node modules like express which provide for this.



I am a traditional Java user and Jersey framework used to provide such a thing in Java.



Thanks,
Tuco


More From » node.js

 Answers
4

Spend some time with the documentation. Express uses the : to denote a variable in a route:



app.get('/user/:id/docs', function(req, res) {
var id = req.params.id;
});

[#83376] Monday, August 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anitamaeg

Total Points: 466
Total Questions: 106
Total Answers: 106

Location: Suriname
Member since Sun, Jun 13, 2021
3 Years ago
;