Day 04 Advanced Topics

Edge Functions

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

~1 hour Hands-on Precision AI Academy

Today’s Objective

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.

Create and deploy
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
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
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. .

Supporting Resources

Go deeper with these references.

Supabase
Supabase Documentation Complete reference for Auth, Database, Storage, Edge Functions, and Realtime.
→
GitHub
Supabase Examples Official collection of quickstarts and example apps in multiple frameworks.
→
YouTube
Supabase YouTube Channel Tutorial videos from the Supabase team covering new features and patterns.
→

Day 4 Checkpoint

Before moving on, make sure you can answer these without looking:

Continue To Day 5
Realtime
→