Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Parameters in cloud code function call? #34

Closed
ghost opened this issue Jan 14, 2019 · 5 comments
Closed

[Question] Parameters in cloud code function call? #34

ghost opened this issue Jan 14, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented Jan 14, 2019

Hi,

Like they show in the REST API Guide (https://docs.parseplatform.org/rest/guide/#cloud-code), is it possible to send parameters to the cloud code ?

For example:
{"plan":"paid"}

curl -X POST \
  -H "X-Parse-Application-Id: y4uNX4YgsoxgvOHOn8Or9owkIF83HI6r4jdsAFJh" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{{"plan":"paid"}}' \
  https://parseapi.back4app.com/functions/hello
@phillwiggins
Copy link
Member

I would imagine you simple extend the ParseFunction as you would a ParseObject. Very similar to how the DietPlan extends ParseObject, but implements a variable called name.

@ghost
Copy link
Author

ghost commented Jan 14, 2019

An idea for next update :

In lib/src/objects/parse_function.dart

execute({Map parameters}) async {
    var uri = _client.data.serverUrl + "$_path";

    if (parameters != null) setObjectData(parameters);

    var result = await _client.post(
        uri, body: JsonEncoder().convert(getObjectData()));
    return super.handleResponse(result, ParseApiRQ.execute);
  }

Sample example, main.dart :

function() async {
    var function = ParseCloudFunction('function');
    var parameters = {'plan': 'paid'};
    var response = await function.execute(parameters: parameters);

    //or
    //var response = await function.execute();

    //...
  }

@ghost
Copy link
Author

ghost commented Jan 21, 2019

Do you think you will implement "my" idea ? (For information, we can do the same with android/iOS SDK : https://docs.parseplatform.org/android/guide/#use-cloud-code )

HashMap<String, String> params = new HashMap();
params.put("movie", "The Matrix");
ParseCloud.callFunctionInBackground("averageStars", params, new FunctionCallback<Float>() {
  @Override
  public void done(Float aFloat, ParseException e) {
    if (e == null) {
      // ratings is 4.5
    }
  }
});

I think i'm not the only one who need it a lot and it will be a good idea for a lot of people.

@phillwiggins
Copy link
Member

phillwiggins commented Jan 21, 2019 via email

@ghost
Copy link
Author

ghost commented Jan 21, 2019

Added in v1.0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant