invoke()
Invokes a Supabase Function. See the guide for details on writing Functions.
final res = await supabaseClient.functions.invoke('hello', body: {'foo': 'baa'});
final data = res.data;
final error = res.error;
Notes
- Requires an Authorization header.
- Invoke params generally match the Fetch API spec.
Examples
Basic invocation.
final res = await supabaseClient.functions.invoke('hello', body: {'foo': 'baa'});
final data = res.data;
final error = res.error;
Specifying response type.
By default, invoke()
will parse the response as JSON. You can parse the response in the following formats: json
, blob
, text
, and arrayBuffer
.
final res = await supabaseClient.functions.invoke(
'hello',
body: {'foo': 'baa'},
responseType: ResponseType.text,
);
final data = res.data;
final error = res.error;
Parsing custom headers.
Any headers
will be passed through to the function. A common pattern is to pass a logged-in user's JWT token as an Authorization header.
final res = await supabaseClient.functions.invoke(
'hello',
body: {'foo': 'baa'},
headers: {
'Authorization': 'Bearer ${supabase.auth.session()?.access_token}'
},
);