Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

FunctionsClient

Client for invoking Supabase Edge Functions.

class FunctionsClient {
constructor(url: string, { headers, customFetch, region }?: {
headers?: Record<string, string>;
customFetch?: Fetch;
region?: FunctionRegion;
}
);
protected fetch: Fetch;
protected headers: Record<string, string>;
protected region: FunctionRegion;
protected url: string;
 
invoke<T = any>(functionName: string, options?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
setAuth(token: string): void;
}

§Constructors

§
new FunctionsClient(url: string, { headers, customFetch, region }?: {
headers?: Record<string, string>;
customFetch?: Fetch;
region?: FunctionRegion;
}
)
[src]

Creates a new Functions client bound to an Edge Functions URL.

@example
import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'

const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
  headers: { apikey: 'public-anon-key' },
  region: FunctionRegion.UsEast1,
})
@example

Creating a Functions client

import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'

const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
  headers: { apikey: 'public-anon-key' },
  region: FunctionRegion.UsEast1,
})

§Properties

§
fetch: Fetch
[src]
§
headers: Record<string, string>
[src]
§
url: string
[src]

§Methods

§
invoke<T = any>(functionName: string, options?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>
[src]

Invokes a function

@param functionName
  • The name of the Function to invoke.
@param options
  • Options for invoking the Function.
@example
const { data, error } = await functions.invoke('hello-world', {
  body: { name: 'Ada' },
})
@example

Basic invocation

const { data, error } = await supabase.functions.invoke('hello', {
  body: { foo: 'bar' }
})
@example
@example

Error handling

import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";

const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  body: { foo: 'bar' }
})

if (error instanceof FunctionsHttpError) {
  const errorMessage = await error.context.json()
  console.log('Function returned an error', errorMessage)
} else if (error instanceof FunctionsRelayError) {
  console.log('Relay error:', error.message)
} else if (error instanceof FunctionsFetchError) {
  console.log('Fetch error:', error.message)
}
@example
@example

Passing custom headers

const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  body: { foo: 'bar' }
})
@example
@example

Calling with DELETE HTTP verb

const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  body: { foo: 'bar' },
  method: 'DELETE'
})
@example
@example

Invoking a Function in the UsEast1 region

import { createClient, FunctionRegion } from '@supabase/supabase-js'

const { data, error } = await supabase.functions.invoke('hello', {
  body: { foo: 'bar' },
  region: FunctionRegion.UsEast1
})
@example
@example

Calling with GET HTTP verb

const { data, error } = await supabase.functions.invoke('hello', {
  headers: {
    "my-custom-header": 'my-custom-header-value'
  },
  method: 'GET'
})
@example

Example 7

const { data, error } = await functions.invoke('hello-world', {
  body: { name: 'Ada' },
})
§
setAuth(token: string): void
[src]

Updates the authorization header

@param token
  • the new jwt token sent in the authorisation header
@example

Setting the authorization header

functions.setAuth(session.access_token)