Supabase Functions
Supabase Edge Functions are runnable functions distributed globally at the edge. They can be used for listening to webhooks or integrating your Supabase project with third-parties.
Supabase Edge Functions are developed using Deno.
Getting Started
Before getting started, you need to install the supabase
CLI - available via NPM, Homebrew & Scoop.
Once installed, start the Supabase services:
supabase start
Next, either use the edge
CLI command or setup manually:
Create a new project using the edge
CLI command:
edge new supabase_functions new_project
This command will create a new barebones template in the current directory. Once complete, install the dependencies:
dart pub get
Next, init the local superbase project using their CLI:
supabase init
This will create a local supabase
directory, which contains various contents used to run your Supabase functions.
Open the lib/main.dart
file to view the minimal HTTP request fetch handler:
void main() {
SupabaseFunctions(fetch: (request) {
return Response("Hello from Supabase Edge Functions!");
});
}
Each incoming request to your edge function will be passed to the fetch
handler, which is expected to return a Response
instance. The fetch
handler provides a Request
instance which contains useful information about the incoming request, such as the method, URL, headers, body and more.
Local development
To run your application locally, first run edge build supabase_functions --dev
command from the root of your project:
edge build supabase_functions --dev
This command will start a build watcher which will recompile any changes you make to your project.
Next run the dart_edge
function:
supabase functions serve dart_edge --no-verify-jwt
Note: By default Supabase Functions expects a valid auth header. The
--no-verify-jwt
enables you to run the function without a valid auth header.
You should now be able to access your function at http://localhost:54321/functions/v1/dart_edge.
To learn more about local Supabase development, view their documentation.