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
- Cant configure email templates
i configure it on the console, and when i send the OTP, it sends with appwrite's email (instead of custom smtp) and with the branding, but i have the Pro (educa...
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...
- Need Help with Google OAuth2 in Expo usi...
I'm learning React Native with Expo and trying to set up Google OAuth2 with Appwrite. I couldn't find any good docs or tutorials for this and my own attempt did...