garrettmac
garrettmac

Reputation: 8585

How-to declare params in Parse.Cloud.define()

This should be an easy enough question. I'm not sure if this is a javascript or parse.com question but when I look at some examples I see variables like the url or params being declared like so:

Parse.Cloud.define('getData', function(request, response) {

      //HERE
      var params = request.params;

      //AND HERE
      var url = params.url;
    ..... 

So my question is where are the params (in params.url) and request (in request.params) being declared before new instances of them are made?

Upvotes: 1

Views: 909

Answers (1)

Henry Situ
Henry Situ

Reputation: 153

This is a parse.com question.

No need to declare var params = request.params;

request.params is automatically declared "and set/populated" by parse.com for every cloud function.

request.params stores the JSON values the caller passed in. For example, if I call getData() in javascript with something like this

Parse.Cloud.run('getData', {
   'nFIObjectId':'a',
   'rRFObject':2,
   'rFOId':'three3'
});

then in your getDate() cloud function, you can start using request.params.nFIObjectId and request.params.rRFObject and request.params.rFOId. Their values are 'a', 2, and 'three3' respectively.

Similarly, if I call getDate() from a curl command like this

curl -X POST   -H "X-Parse-Application-Id: asdf23lj4lkjasldkfjasldfkjasklja"   -H "X-Parse-REST-API-Key: 123ou234laskjdfiuj3kjasdf"   -H "Content-Type: application/json"   -d '{  "nFIObjectId":"a", "rRFObject":2, "rFOId":"three3"  }' https://api.parse.com/1/functions/getData

your getDate() cloud function will get the same values for those 3 input parameters.

Upvotes: 1

Related Questions