What is an Edge Function in the context of Supabase and Deno?
An Edge Function is a small piece of code that runs close to users on the network edge, using Deno runtime in Supabase. It helps respond quickly to requests by running near the user instead of a central server.
Click to reveal answer
beginner
Why use Deno for Edge Functions instead of Node.js?
Deno is secure by default, supports modern JavaScript and TypeScript without extra setup, and is lightweight, making it ideal for fast, small edge functions.
Click to reveal answer
beginner
How do you deploy an Edge Function in Supabase using Deno?
You write your function code in a file, then use the Supabase CLI command `supabase functions deploy ` to upload and activate it on the edge.
Click to reveal answer
intermediate
What is the role of the `Request` and `Response` objects in a Deno Edge Function?
The `Request` object contains details about the incoming user request, like headers and body. The function processes it and returns a `Response` object with status, headers, and body to send back.
Click to reveal answer
intermediate
Name one best practice when writing Edge Functions with Deno on Supabase.
Keep functions small and fast, avoid long-running tasks, and handle errors gracefully to ensure quick responses and reliability at the edge.
Click to reveal answer
What runtime does Supabase use for its Edge Functions?
ARuby
BNode.js
CDeno
DPython
✗ Incorrect
Supabase Edge Functions run on the Deno runtime, which is designed for secure and fast execution.
Which command deploys an Edge Function in Supabase?
Adeno deploy <function-name>
Bsupabase functions deploy <function-name>
Csupabase deploy edge <function-name>
Dsupabase edge run <function-name>
✗ Incorrect
The correct command to deploy an Edge Function is `supabase functions deploy `.
What is a key benefit of running functions at the network edge?
AFaster response times to users
BMore storage space
CEasier database management
DLonger function execution time
✗ Incorrect
Running functions at the edge reduces distance to users, resulting in faster responses.
Which language can you write Edge Functions in when using Supabase with Deno?
ATypeScript
BJava
CPHP
DC++
✗ Incorrect
Deno supports TypeScript natively, so you can write Edge Functions in TypeScript.
What should you avoid in Edge Functions to keep them efficient?
AUsing environment variables
BUsing HTTP requests
CReturning responses
DLong-running tasks
✗ Incorrect
Long-running tasks slow down edge functions and reduce performance; keep them short and fast.
Explain how to create and deploy an Edge Function using Deno on Supabase.
Think about the steps from coding to deployment and runtime environment.
You got /4 concepts.
Describe the benefits of running functions at the edge with Deno in Supabase.
Consider speed, security, and language features.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of creating Edge Functions with Deno in Supabase?
easy
A. To run code close to users for faster response times
B. To store large amounts of data in the cloud
C. To create user interfaces for web apps
D. To manage database schemas automatically
Solution
Step 1: Understand Edge Functions role
Edge Functions run code near users to reduce delay and improve speed.
Step 2: Compare options
Only To run code close to users for faster response times describes running code close to users for faster responses, which matches Edge Functions purpose.
Final Answer:
To run code close to users for faster response times -> Option A
Quick Check:
Edge Functions = run code near users [OK]
Hint: Edge Functions speed up responses by running near users [OK]
Common Mistakes:
Confusing Edge Functions with database storage
Thinking Edge Functions build UI
Assuming Edge Functions manage schemas
2. Which of the following is the correct way to start an Edge Function using Deno's serve method?
easy
A. Response(serve(() => 'Hello from Edge!'))
B. serve = new Response('Hello from Edge!')
C. new serve(() => Response('Hello from Edge!'))
D. serve(() => new Response('Hello from Edge!'))
Solution
Step 1: Recall Deno serve syntax
Deno's serve function takes a handler function returning a Response object.
Step 2: Check options
serve(() => new Response('Hello from Edge!')) correctly calls serve with a function returning new Response. Others misuse syntax or order.
Final Answer:
serve(() => new Response('Hello from Edge!')) -> Option D
Quick Check:
serve(handler returning Response) = correct [OK]
Hint: serve needs a function returning new Response [OK]
Common Mistakes:
Assigning serve instead of calling it
Using Response without new keyword
Passing string directly instead of Response
3. Given this Edge Function code snippet, what will be the response text when a request is made?
import { serve } from "https://deno.land/std/http/server.ts";
serve(() => new Response('Edge Function Active'));
medium
A. Edge Function Active
B. undefined
C. Error: serve not found
D. No response
Solution
Step 1: Analyze the code
The serve function is imported correctly and called with a handler returning Response with text 'Edge Function Active'.
Step 2: Determine output
When a request arrives, the handler returns Response with body 'Edge Function Active', so that text is sent back.
Final Answer:
Edge Function Active -> Option A
Quick Check:
serve returns Response text = 'Edge Function Active' [OK]
Hint: Response text is what handler returns inside new Response() [OK]
Common Mistakes:
Assuming serve is undefined without import
Expecting no response without explicit return
Confusing Response object with string
4. Identify the error in this Edge Function code snippet:
import { serve } from "https://deno.land/std/http/server.ts";
serve(() => Response('Hello'));
medium
A. serve is not imported correctly
B. Missing 'new' keyword before Response
C. Arrow function syntax is invalid
D. Response cannot be used in Edge Functions
Solution
Step 1: Check Response usage
Response is a class and must be instantiated with 'new'. The code calls Response() without 'new'.
Step 2: Verify other parts
serve is imported correctly, arrow function syntax is valid, and Response is allowed in Edge Functions.
Final Answer:
Missing 'new' keyword before Response -> Option B
Quick Check:
Response needs 'new' keyword [OK]
Hint: Always use 'new Response()' to create response objects [OK]
Common Mistakes:
Forgetting 'new' before Response
Assuming serve import is wrong
Thinking arrow function syntax is incorrect
5. You want to create an Edge Function that returns JSON data with a message and status code 200. Which code snippet correctly implements this using Deno's serve?
hard
A. serve(() => new Response({ message: 'Success' }, { headers: { 'Content-Type': 'application/json' } }))