Day 4 of 5
⏱ ~60 minutes
Supabase in 5 Days — Day 4

Edge Functions

Write Deno TypeScript functions at the edge, call external APIs, and handle webhooks.

What Edge Functions Are

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.

Create and deploy
# 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
supabase/functions/send-welcome-email/index.ts
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' } }); });
Call from your app
const { data, error } = await supabase.functions.invoke('send-welcome-email', {
  body: { email: user.email, name: user.name }
});
📝 Day 4 Exercise
Write an Edge Function
  1. C
  2. r
  3. e
  4. a
  5. t
  6. e
  7. a
  8. S
  9. u
  10. p
  11. a
  12. b
  13. a
  14. s
  15. e
  16. e
  17. d
  18. g
  19. e
  20. f
  21. u
  22. n
  23. c
  24. t
  25. i
  26. o
  27. n
  28. t
  29. h
  30. a
  31. t
  32. a
  33. c
  34. c
  35. e
  36. p
  37. t
  38. s
  39. a
  40. P
  41. O
  42. S
  43. T
  44. r
  45. e
  46. q
  47. u
  48. e
  49. s
  50. t
  51. w
  52. i
  53. t
  54. h
  55. a
  56. m
  57. e
  58. s
  59. s
  60. a
  61. g
  62. e
  63. a
  64. n
  65. d
  66. u
  67. s
  68. e
  69. r
  70. I
  71. D
  72. ,
  73. a
  74. n
  75. d
  76. s
  77. t
  78. o
  79. r
  80. e
  81. s
  82. i
  83. t
  84. i
  85. n
  86. a
  87. S
  88. u
  89. p
  90. a
  91. b
  92. a
  93. s
  94. e
  95. t
  96. a
  97. b
  98. l
  99. e
  100. .
  101. T
  102. e
  103. s
  104. t
  105. i
  106. t
  107. w
  108. i
  109. t
  110. h
  111. c
  112. u
  113. r
  114. l
  115. .
  116. C
  117. a
  118. l
  119. l
  120. i
  121. t
  122. f
  123. r
  124. o
  125. m
  126. y
  127. o
  128. u
  129. r
  130. R
  131. e
  132. a
  133. c
  134. t
  135. a
  136. p
  137. p
  138. a
  139. f
  140. t
  141. e
  142. r
  143. a
  144. u
  145. s
  146. e
  147. r
  148. c
  149. r
  150. e
  151. a
  152. t
  153. e
  154. s
  155. a
  156. p
  157. o
  158. s
  159. t
  160. .

Day 4 Summary

  • Edge functions run Deno TypeScript. Access environment secrets with Deno.env.get('KEY').
  • supabase functions deploy name → callable via supabase.functions.invoke('name', { body }).
  • Edge functions run globally distributed — low latency from anywhere.
  • Store secrets in Supabase project settings → Edge Functions → Secrets.
Finished this lesson?