Skip to main content

supabase_functions 3.0.0-dev.12 copy "supabase_functions: ^3.0.0-dev.12" to clipboard
supabase_functions: ^3.0.0-dev.12 copied to clipboard

A dart client library for the Supabase functions.


Supabase Logo

supabase_functions

Dart client library to interact with Supabase Edge Functions.

Guides · Reference Docs

pub package pub test

Note

This package was published as functions_client up to and including v2. That package is discontinued in favour of supabase_functions.

Usage #

In an app that uses supabase or supabase_flutter, invoke functions through supabase.functions, which sends the API key and the access token of the signed-in user for you:

final response = await supabase.functions.invoke(
  'hello-world',
  body: {'name': 'Ada'},
);
print('${response.statusCode}: ${response.data}');
print(response.headers['content-type']);

data depends on the Content-Type of the response: application/json and every +json type are decoded, with an empty body as null, application/octet-stream is a Uint8List, text/event-stream is a ByteStream to listen to, and every other type is a String. The response headers are in headers.

Standalone, create a FunctionsClient with the functions URL of your project and the apikey header. Pass accessToken to send the token of a signed-in user as Authorization: Bearer <token>. With a legacy JWT anon key, a function that verifies the JWT also needs the key as Authorization: Bearer <key> when no user is signed in:

import 'package:supabase_functions/supabase_functions.dart';

Future<void> main() async {
  final functions = FunctionsClient(
    'https://your-project.supabase.co/functions/v1',
    {'apikey': 'your-publishable-key'},
  );

  try {
    final response = await functions.invoke(
      'hello-world',
      method: HttpMethod.get,
      queryParameters: {'name': 'Ada'},
      region: FunctionsRegion.euWest1,
    );
    print(response.data);
  } on FunctionsApiException catch (error) {
    print('The function failed: ${error.statusCode} ${error.details}');
  } on FunctionsException catch (error) {
    print('The invocation failed: ${error.message}');
  } finally {
    await functions.dispose();
  }
}

A non-2xx response throws a FunctionsApiException with the status code and the response body as details. A request that gets no response throws a FunctionsFetchException, and an error of the Supabase relay a FunctionsRelayException. All three extend FunctionsException. When the error body is a JSON object, its message and code become the message and errorCode of the exception.

Supabase Service Compatibility #

supabase_functions only guarantees compatibility with the latest Supabase Edge Runtime release. Older Supabase Edge Runtime releases are supported on a best-effort basis, but compatibility is not guaranteed.

If you self-host the Supabase Edge Runtime, we recommend upgrading to the latest release when upgrading this SDK.

Docs #

The docs can be found on the official Supabase website.

License #

This repo is licensed under MIT.

Credits #