Files
supabase/apps/reference/_supabase_dart/invoke.mdx
T

135 lines
2.4 KiB
Plaintext

---
id: invoke
title: "invoke()"
slug: invoke
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/dart.yml
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
Invokes a Supabase Function. See the [guide](/docs/guides/api) for details on writing Functions.
:::caution
Supabase Functions are in Experimental release until 1 August 2022. There will breaking changes. Do not use them in Production.
:::
We have released Supabase Functions to gather feedback. You're welcome to try them out and send us feedback but we strongly advise against using them for anything in production.
There will be breaking changes with no notice.
<Tabs
defaultValue="dart"
groupId="reference/dart"
values={[{ label: 'Dart', value: 'dart' }]}>
<TabItem value="dart">
```dart
final res = await supabaseClient.functions.invoke('hello', body: {'foo': 'baa'});
final data = res.data;
final error = res.error;
```
</TabItem>
</Tabs>
## Notes
- Requires an Authorization header.
- Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
## Examples
### Basic invocation.
<Tabs
defaultValue="dart"
groupId="reference/dart"
values={[{ label: 'Dart', value: 'dart' }]}>
<TabItem value="dart">
```dart
final res = await supabaseClient.functions.invoke('hello', body: {'foo': 'baa'});
final data = res.data;
final error = res.error;
```
</TabItem>
</Tabs>
### 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`.
<Tabs
defaultValue="dart"
groupId="reference/dart"
values={[{ label: 'Dart', value: 'dart' }]}>
<TabItem value="dart">
```dart
final res = await supabaseClient.functions.invoke(
'hello',
body: {'foo': 'baa'},
responseType: ResponseType.text,
);
final data = res.data;
final error = res.error;
```
</TabItem>
</Tabs>
### 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.
<Tabs
defaultValue="dart"
groupId="reference/dart"
values={[{ label: 'Dart', value: 'dart' }]}>
<TabItem value="dart">
```dart
final res = await supabaseClient.functions.invoke(
'hello',
body: {'foo': 'baa'},
headers: {
'Authorization': 'Bearer ${supabase.auth.session()?.access_token}'
},
);
```
</TabItem>
</Tabs>