0

I have an object, like this:

$scope.user = {name: "Jim", birthday: "1/1/90", address: "123 Easy St"}

I'm making an $http call to my server and I'd like to pass this user info. I'm trying like this:

$http({
    url: '/api/coolLookup/' + userID, 
    method: "GET",
    params: {user:$scope.user}
  }).success(function(data){
      // do stuff
  });

Within my server resource (I'm using ExpressJS/Node here) I'm trying to access the user object but cannot:

exports.coolLookup = function (req, res) {
    console.log("Here's the user")
    console.log(req.params.user)
}

req.params.user returns undefined in my console. Any idea what to do here?

JVG
  • 20,198
  • 47
  • 132
  • 210

1 Answers1

1

In Express you should do:

console.log(req.query.user);

(NOTE: query, not params)

This will give you a string, use JSON.parse() to convert it to an object.

Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90
  • Ah, beauty. `req.params.query` correctly returns the search params so it tripped me up. – JVG Oct 21 '13 at 11:09