0
0
Supabasecloud~30 mins

Creating Edge Functions with Deno in Supabase - Try It Yourself

Choose your learning style9 modes available
Creating Edge Functions with Deno
📖 Scenario: You are building a simple serverless function using Deno on Supabase Edge Functions. This function will respond to HTTP requests with a greeting message. Edge Functions run close to users for fast responses.
🎯 Goal: Create a basic Edge Function using Deno that returns a JSON greeting message when called.
📋 What You'll Learn
Create a new Edge Function file named hello.ts.
Define a handler function that accepts a Request object.
Return a JSON response with a greeting message.
Export the handler as the default export.
💡 Why This Matters
🌍 Real World
Edge Functions let you run code close to users without managing servers. This improves speed and scalability for web apps.
💼 Career
Knowing how to write and deploy Edge Functions is valuable for cloud developers working with serverless architectures and modern backend services.
Progress0 / 4 steps
1
Create the Edge Function file
Create a new file named hello.ts and define an async function called handler that accepts a single parameter request of type Request. For now, leave the function body empty.
Supabase
Hint

Start by writing the function signature for handler with async and a request parameter.

2
Create a JSON response object
Inside the handler function, create a constant called responseBody and assign it an object with a single key message and value "Hello from Supabase Edge Function!".
Supabase
Hint

Use const responseBody = { message: "Hello from Supabase Edge Function!" } inside the function.

3
Return the JSON response
Return a new Response object from the handler function. Use JSON.stringify(responseBody) as the body, and set the Content-Type header to application/json.
Supabase
Hint

Use return new Response(JSON.stringify(responseBody), { headers: { "Content-Type": "application/json" } }).

4
Export the handler as default
Add a default export statement at the end of the file to export the handler function.
Supabase
Hint

Write export default handler; at the end of the file.