Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

query string - How to parse/read multiple parameters with restify framework for Node.JS

Scenario: We developer are trying to replace a web service (written in C#.Net) with Node.JS Restful API.

Issue: Now we need to handle the incoming request as is (we don't have control over it). So the following is the format of the incoming URL:

http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324&GetDetailType=FULL

I am able to handle the URL like:

http://www.website.com/service/Trans001/ae67ea324/FULL

I can parse/read the parameter from the above URL

Code:

var server = require('restify').createServer();
function respond(req, res, next) {
    console.log("req.params.UID:" + req.params.UID);
    console.log("req.params.FacebookID:" + req.params.FacebookID);
    console.log("req.params.GetDetailType" + req.params.GetDetailType);
}
server.get('/service/:UID/:FacebookID/:GetDetailType', respond);
server.listen(8080, function () {
    console.log('%s listening at %s', server.name, server.url);
});

Question: How can I read the multiple parameters from the URL which is formatted like http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You just need to load the query parser plugin like so;

server.use(restify.plugins.queryParser());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...