invoke()
Invokes a Supabase Function.
caution
Edge Functions are Experimental 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.
- JavaScript
const { data: user, error } = await supabase.functions.invoke('hello', {
body: JSON.stringify({ foo: 'bar' })
})
Parameters
functionNamerequired
string
the name of the function to invoke
invokeOptionsoptional
FunctionInvokeOptions
object with the following properties
headers
: object representing the headers to send with the requestbody
: the body of the requestresponseType
: how the response should be parsed. The default isjson
Notes
- Requires an Authorization header.
- Invoke params generally match the Fetch API spec.
Examples
Basic invocation.
- JavaScript
const { data: user, error } = await supabase.functions.invoke('hello', {
body: JSON.stringify({ foo: 'bar' })
})
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
.
- JavaScript
const { data: user, error } = await supabase.functions.invoke('hello', {
responseType: 'text',
body: JSON.stringify({ foo: 'bar' })
})
Parsing custom headers.
You can pass custom headers to your function. Note: supabase-js automatically passes the Authorization
header with the signed in user's JWT.
- JavaScript
const { data: user, error } = await supabase.functions.invoke('hello', {
headers: {
"my-custom-header": 'my-custom-header-value'
},
body: JSON.stringify({ foo: 'bar' })
})