Back

[SOLVED] I am trying to write a dart functions on Appwrite Cloud.

  • 0
  • Functions
  • Cloud
prasadsunny1
3 Sep, 2023, 07:52

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

TL;DR
Title: [SOLVED] Syntax for writing Dart functions on Appwrite Cloud - User was able to solve their issue - Provided working example of a Dart function using print statements for logging messages - Noted that log and error methods (`context.log`, `context.error`) are not available in the current version of Appwrite Cloud - Shared link to Appwrite Cloud documentation for functions development - Noted that the entrypoint signature has changed from `Future main(final context) async {` to `Future start(final req, final res) async {` - Provided a working example of a Dart function with the new entrypoint
prasadsunny1
3 Sep, 2023, 07:53
darShan
3 Sep, 2023, 08:14

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:

TypeScript
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,
  });
}
prasadsunny1
3 Sep, 2023, 08:43

Nice, Thanks

prasadsunny1
3 Sep, 2023, 11:36

Do you know if atleast log is possible

darShan
3 Sep, 2023, 11:41

you can use print to log messages if thats what you mean.

darShan
3 Sep, 2023, 11:42

something like: print("Hi there 👋")

prasadsunny1
3 Sep, 2023, 11:55

Worked

darShan
3 Sep, 2023, 11:59

Great!

Drake
3 Sep, 2023, 20:32

[SOLVED] I am trying to write a dart functions on Appwrite Cloud.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more