The api layer behind restful?


Is there an api layer which could accept where condition json data as input parameter?

Since this is a must part behind restful api, so I think there must be something like this? But not sure if it is an api layer which could be used by developers?

Thanks a lot.

I am not sure I understood what you need to know. Could you please explain what you want to achieve?

@davimacedo Sorry for the confusion. For example, below is the restful sample from:

curl -X GET \
  -H "X-Parse-Application-Id: APPLICATION_ID" \
  -H "X-Parse-REST-API-Key: REST_API_KEY" \
  -G \
  --data-urlencode 'where={"score":{"$gte":1000,"$lte":3000}}' \

I think the process flow on parse server side should be something like:

  let whereJson = query.where;  // {"score":{"$gte":1000,"$lte":3000}}
  let result = XXX.findMethod(whereJson, GameScore); // return the query result with where filter 

And now assuming that the 3000 can not be passed from client, which need to be calculated on server side based on APPLICATION_ID instead. To achieve this, seems we could only use cloud code? Something as below:

  let lteValue = getLteValue(APPLICATION_ID);  // maybe stored in the mongodb
  let whereJson = query.where;
  whereJson.score.$lte = lteValue;  // construct the $lte attribute value on server side
  let result = XXX.findMethod(whereJson, GameScore); // return the query result with where filter

So, my question is: is the XXX.findMethod or similar api (which accepts where filter json as input parameter) exists?

If still anything unclear, please just let me know. Thanks!

My this question is somewhat derived from this post:

I think you have two options to achieve what you need:

  • Make the class not readable via CLP and create a cloud code function to perform the query (using master key) with the constraints that you need.
  • Add a beforeFind trigger to your class that automatically includes the $lte constraint.

@davimacedo Thanks for kind help, I understood that I could use the beforeFind trigger, while just did not find the “findMethod” API in document, which could have the whereJson parameter.

From find method in js api, seems options parameter have no query condition json info?

I also found the fromJSON and withJSON, but not sure if they are related. And also, seems the doc for withJSON is not accurate, since the example there has NO withJSON wording, only fromJSON …

What you need to do is something like this:

Parse.Cloud.beforeFind('GameScore', (req) => {
  const query = req.query; // the Parse.Query
  const lteValue = getLteValue(APPLICATION_ID);
  query.lessThanOrEqualTo('score', lteValue);
1 Like