Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sails.js and multiple parameters

I have been playing with node.js and more recently sails.js. In node.js I was using express and so it was easy to define multiple paramters by using Routers.get however I am struggling in sails.

I have created a api using the built in command and noticed that this will take one param that defaults to a name of id, this is fine if I just wish to use the one param but I am trying to call a function that fires a stored procedure that requires 4 params. These are being called via an Android device.

Using node I was sending something like

myserveraddress/sendgrn/" + 1 + "/" + User + "/" + 1111 + "/" + 22)

This doesn;t work in sails, can anyone point me in the right direction?

like image 252
dave Avatar asked Sep 14 '26 06:09

dave


2 Answers

In your config/route.js you could also have manually defined a route like this :

'POST /sendgrn/:param1/:param2/:param3/:param4' : "SomeController.sendgrn"

And then to get your params in your controller method for instance :

sendgrn: function(req, res){
    var p1 = req.param("param1");
    var p2 = req.param("param2");
    ... 
    // do something with the params
}

More about routes syntax in sails : here

like image 139
Khopa Avatar answered Sep 16 '26 09:09

Khopa


In the end I used the default create method and added my params like:

/myserver/myroute/create?param1=1&param2=2 etc

like image 31
dave Avatar answered Sep 16 '26 07:09

dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!