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
- 408 Timeout / Curl Error 7 in Executor w...
Hey everyone, I am losing my mind over a routing loop/timeout issue on a fresh self-hosted setup. I have a single Linux VPS (IP: 45.141.37.105) and one domain (...
- functions returning error 401 in local
I updated to 1.9.0, and the functions that used to work fine in 1.8.1 are now giving me a 401 error. I can't seem to find a solution. If anyone is running versi...
- User Blocked - False Positive
Today I tried to log in to my cloud console and it said the user is blocked and I didn't even receive any email regarding this like what kind of violation is my...