I'm trying to send a GET request from a Node.js app to a Rails server. Currently, I am using the request module like so:
var request = require("request");
var url = 'www.example.com'
function sendRequest(url){
string = 'http://localhost:3000/my-api-controller?url=' + url;
request.get(string, function(error, response, body){
console.log(body);
});
}
This works. But what I would like is not to build the string for a get request, but to pass parameters of the request as a javascript object (in a jQuery-like fashion). There is one example on the wiki page of the request module that uses exactly this kind of syntax:
request.get('http://some.server.com/', {
'auth': {
'user': 'username',
'pass': 'password',
'sendImmediately': false
}
});
However, when I tried to adapt this syntax for my purposes like so:
function sendRequest(url){
request.get('http://localhost:3000/my-api-controller', {url: url}, function(error, response, body){
console.log(body);
});
}
the url parameter did not get sent.
So my question is, am I doing something wrong here or does the request module not support passing parameters of a get request as a javascript object? And if it doesn't, could you suggest a handy Node module that does?