Expand the Create Execution /v1/functions/{functionId}/executions api so that it accepts custom data and make it available as an Environment variable to the function container.
No, but I was instructed to open an issue by @eldadfux.
Yes.
Right now, functions are great for recurring, or event driven tasks, but they cannot accept additional data, which makes them not very useful if user input or other data is needed.
I'm currently working on a project where users can create Orders if certain requirements are fulfilled. They can't have write access to the orders collection because the requirements wouldn't be checked. I don't want to write a full backend for this one problem, so my current workaround is to have a Job/Queue Collection and a function that gets triggered when new documents show up in the queue, which contains the additional data.
That is obviously neither pretty, nor does it allow for very good user feedback. It also makes permission checking much more difficult than it would need to be.
This is just a single example, but I hope it's easy to see that being able to pass additional data to functions and also knowing who called them (if they were called by a user) would make functions much more powerful. In theory this could enable appwrite to accomodate very complex serverless applications.
This would definitely make a great addition to the REST API. I was thinking to introduce a new param called data which will just accept plain text. Passing the data as plain text will make our life easier with GraphQL (no support for non-structured objects) and anyway the function is only able to get primitive env vars and not complex objects.
Client could pass a JSON string and parse it within the function itself. This will also require us to allow passing this data when executing a function from the Appwrite console.
Another idea we discussed, is to pass the user ID for the user who submitted the request, this should only be done if the user has a valid authenticated session to ensure the function itself doesn't have to verify the user. We can use the APPWRITE_FUNCTION_USER_ID env var to pass this data to the function.
We should also consider to pass a valid JWT secret to the function and easily allow the custom code to act on behalf of the user using any of the supported Appwrite APIs or SDK. We need to check the JWT performance to make sure this does not create any significant as not all functions need to use it. JWT should be generated only if the request was executed by a logged in user (not an API key). We can use APPWRITE_FUNCTION_JWT as the env var name.
@TJennerjahn We're aiming to include these features in our 0.8 release (in a few weeks), but we're starting to put the pieces together now. Stay tuned!
This feature is available on the 0.8.x branch if anyone wishes to test it out.