Write Deno TypeScript functions at the edge, call external APIs, and handle webhooks.
Supabase Edge Functions run Deno TypeScript at Cloudflare's edge. They're perfect for: webhook handlers, sending emails, calling third-party APIs (Stripe, Twilio), and logic you don't want in the browser.
# Install Supabase CLI npm install -g supabase supabase login supabase init # Create a function supabase functions new send-welcome-email # Deploy supabase functions deploy send-welcome-email
import { serve } from 'https://deno.land/[email protected]/http/server.ts';
serve(async (req) => { const { email, name } = await req.json(); // Send email via Resend (or any email API) const res = await fetch('https://api.resend.com/emails', { method: 'POST', headers: { 'Authorization': `Bearer ${Deno.env.get('RESEND_API_KEY')}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ from: '[email protected]', to: email, subject: 'Welcome!', html: `Hi ${name}!
Thanks for signing up.
` }) }); return new Response(JSON.stringify({ ok: res.ok }), { headers: { 'Content-Type': 'application/json' } });
}); const { data, error } = await supabase.functions.invoke('send-welcome-email', { body: { email: user.email, name: user.name }
}); Before moving on, make sure you can answer these without looking: