0

I'm trying to retrieve the parameters of a GET request as follows but anything I try logs out as 'undefined':

GET

// Find a list of Players
$scope.find = function() {
    $scope.players = Players.query({limit: 50});
};

Middleware

//Players service
angular.module('players').factory('Players', ['$resource',
function($resource) {
    return $resource('players/:playerId', { playerId: '@_id'
    }, {
        update: {
            method: 'PUT'
        }
    });
}
]);

End Point

exports.list = function(req, res) { 

Player.find().sort('-created').limit(req.body.limit).populate('user', 'displayName').exec(function(err, players) {
    if (err) {
        return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
        });
    } else {
        res.jsonp(players);
    }
});
};
Matt D. Webb
  • 3,216
  • 4
  • 29
  • 51

2 Answers2

0

A good discussion on GET with message body - Is this statement correct? HTTP GET method always has no message body

In short, the behavior of servers when using message body with GET would probably not be consistent.

Community
  • 1
  • 1
Nirmal
  • 51
  • 1
  • 1
  • 3
0

As my request is a GET I need to attain the parameters (within the query string) using .query:

Player.find().sort('-created').limit(req.query.limit).populate('user', 'displayName').exec(function(err, players) {
    if (err) {
        return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
        });
    } else {
        res.jsonp(players);
    }
  });
};

This answer was greatly helpful More info

Community
  • 1
  • 1
Matt D. Webb
  • 3,216
  • 4
  • 29
  • 51