📚Academy
likeone
online
MODULE 2 · 260 XP

Edge Functions

Edge functions are serverless code that runs close to your users. Write once, deploy globally, pay per invocation. Supabase edge functions use Deno (TypeScript runtime).

What you're building in this lesson

By the end of this lesson, you'll have written three edge functions from scratch: a simple "Hello World" response, a JSON API that reads user input, and a database-connected function that queries real data. These are the same building blocks behind every modern web API.

What are edge functions?

Think of edge functions as mini-programs that live on the internet. Instead of running on your laptop, they run on servers spread around the world, close to wherever your users are. When someone visits your app from Tokyo, the edge function runs in Tokyo. From London? It runs in London. This makes everything faster.

You don't need to manage servers, install software, or worry about scaling. You just write a small function, deploy it, and it's available to the whole world instantly. You only pay when someone actually uses it.

What is Deno?

Deno is a modern JavaScript runtime — think of it as the engine that runs your code on the server. If you've heard of Node.js, Deno is its newer, more secure sibling. Supabase chose Deno because it starts up faster (important for edge functions) and has better security defaults. You write the same JavaScript/TypeScript you already know — Deno just runs it.

Challenge 1: Hello World

Why this matters

Every API you've ever used — weather apps, payment systems, social media feeds — works by sending and receiving JSON responses. This first challenge teaches you the most fundamental skill in backend development: making a function that responds when someone calls it. Once you can do this, you can build anything.

1
Return a JSON response

Write an edge function that returns {"message": "Hello from the edge!"}

Your task: Fill in the empty return new Response() below. You need to put JSON.stringify({message: "Hello from the edge!"}) inside the Response, and add a Content-Type header. Try writing it yourself before looking at Challenge 2 for the pattern.

index.ts
response
supabase/functions/hello/index.ts

Simulated terminal — in production, you'd see this output in your Supabase dashboard after running supabase functions deploy from your real terminal.

Challenge 2: JSON API

Why this matters

Challenge 1 always returned the same thing. But real APIs need to read what the user sends and respond differently. This is how login forms, search bars, and checkout buttons work — your frontend sends data, and your edge function processes it and responds. This pattern is the backbone of every interactive web app.

2
Parse request body and respond

Upgrade your function: read a JSON body with a name field and respond with a greeting.

Study the code below, then try modifying it: change the greeting message, add a second field (like age), or return different responses based on the name. The code is provided as a reference — understanding why each line exists is the real skill.

index.ts
supabase/functions/greet/index.ts

Simulated terminal — in production, you'd run this from your local terminal and see results in your Supabase dashboard.

🔒

This lesson is for Pro members

Unlock all 300+ lessons across 30 courses with Academy Pro. Founding members get 90% off — forever.

Already a member? Sign in to access your lessons.

Academy
Built with soul — likeone.ai