supabase_functions 3.0.0-dev.12
supabase_functions: ^3.0.0-dev.12 copied to clipboard
A dart client library for the Supabase functions.
supabase_functions
Dart client library to interact with Supabase Edge Functions.
Note
This package was published as
functions_clientup to and including v2. That package is discontinued in favour ofsupabase_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 #
- https://github.com/supabase/functions-js - ported from supabase/functions-js fork