All the docs mention entrypoint signature as Future main(final context) async {
Which I think is deprecated and I found new signature as Future start(final req, final res) async {
The issue is that, I do not know how to find context.log, context.error
Also are there any working examples for dart functions because I am getting stuck in using request and response objects
Cloud isn't on the latest version of appwrite yet.
I'm not sure the correct syntax for functions on 1.1.2, but can you try:
import 'dart:math';
import 'dart:async';
Future <void> start(final req, final res) async {
final payload =
!req.payload?.isEmpty ? req.payload :
'No payload provided. Add custom data when executing function.';
final secretKey = req.variables['SECRET_KEY'] ??
'SECRET_KEY variable not found. You can set it in Function settings.';
final randomNumber = new Random().nextDouble();
final trigger = req.variables['APPWRITE_FUNCTION_TRIGGER'];
// you can also use print("Your message here");
// sends json response back
res.json({
'message': 'Hello from Appwrite!',
'payload': payload,
'secretKey': secretKey,
'randomNumber': randomNumber,
'trigger': trigger,
});
}
Nice, Thanks
Do you know if atleast log is possible
you can use print to log messages if thats what you mean.
something like: print("Hi there 👋")
Worked
Great!
[SOLVED] I am trying to write a dart functions on Appwrite Cloud.
Recommended threads
- Locked out from my own account
I've create an appwrite account using onedevcontext@gmail.com and tried upgrading to Pro multiple times but failed as the Credit Card would not be accepted, I t...
- Not able to upgrade to Appwrite Pro
This is my project ID - 69f5bee60036512d2d52 I've tried multiple credit cards now and I still face the same error "Your card was declined". But I've used the s...
- Storage System
Hey guys, quick question regarding massive storage scaling. I’m working in digital forensics and I’m constantly dealing with huge binary disk images, usually be...