Invoke a Supabase Edge Function.
String
, and Data
. If it doesn't match any of these types we assume the payload is json
, serialize it and attach the Content-Type
header as application/json
. You can override this behaviour by passing in a Content-Type
header of your own.struct Response: Decodable \{
// Expected response definition
\}
let response: Response = try await supabase.functions
.invoke(
"hello",
options: FunctionInvokeOptions(
body: ["foo": "bar"]
)
)
let response = try await supabase.functions
.invoke(
"hello",
options: FunctionInvokeOptions(
body: ["foo": "bar"]
),
decode: \{ data, response in
String(data: data, encoding: .utf8)
\}
)
print(type(of: response)) // String?
do \{
let response = try await supabase.functions
.invoke(
"hello",
options: FunctionInvokeOptions(
body: ["foo": "bar"]
)
)
\} catch FunctionsError.httpError(let code, let data) \{
print("Function returned code \(code) with response \(String(data: data, encoding: .utf8) ?? "")")
\} catch FunctionsError.relayError \{
print("Relay error")
\} catch \{
print("Other error: \(error.localizedDescription)")
\}
let response = try await supabase.functions
.invoke(
"hello",
options: FunctionInvokeOptions(
headers: [
"my-custom-header": "my-custom-header-value"
]
)
)
let response = try await supabase.functions
.invoke(
"hello",
options: FunctionInvokeOptions(
method: .delete,
headers: [
"my-custom-header": "my-custom-header-value"
],
body: ["foo": "bar"]
)
)
let response = try await supabase.functions
.invoke(
"hello",
options: FunctionInvokeOptions(
method: .get,
headers: [
"my-custom-header": "my-custom-header-value"
]
)
)