Learn Supabase-edge-functions - 10 Code Examples & CST Typing Practice Test
Supabase Edge Functions are serverless functions deployed at the edge using Deno runtime, enabling developers to run backend logic close to users with low latency.
View all 10 Supabase-edge-functions code examples →
Learn SUPABASE-EDGE-FUNCTIONS with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple Supabase Edge Function (TypeScript)
# supabase/demo/hello.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((_req) => {
return new Response('Hello, Supabase!', { status: 200 });
});
A simple Supabase Edge Function that returns 'Hello, Supabase!' to HTTP requests.
Supabase Edge Function Returning JSON
# supabase/demo/json.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((_req) => {
const data = { message: 'Hello JSON!' };
return new Response(JSON.stringify(data), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
});
A Supabase Edge Function that returns JSON data.
Supabase Edge Function with Query Parameters
# supabase/demo/query.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((req) => {
const url = new URL(req.url);
const name = url.searchParams.get('name') || 'Guest';
return new Response(`Hello, ${name}!`, { status: 200 });
});
Reads query parameters and responds accordingly.
Supabase Edge Function Handling POST Request
# supabase/demo/post.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve(async (req) => {
if (req.method === 'POST') {
const body = await req.json();
return new Response(JSON.stringify({ received: body }), { status: 200, headers: { 'Content-Type': 'application/json' } });
}
return new Response('Method Not Allowed', { status: 405 });
});
Handles POST request JSON body and responds.
Supabase Edge Function Returning HTML
# supabase/demo/html.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((_req) => {
const html = '<!DOCTYPE html><html><body><h1>Hello HTML!</h1></body></html>';
return new Response(html, { status: 200, headers: { 'Content-Type': 'text/html' } });
});
Responds with a simple HTML page.
Supabase Edge Function with Custom Headers
# supabase/demo/headers.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((_req) => {
return new Response('Custom headers added', { status: 200, headers: { 'X-Custom-Header': 'SupabaseEdge' } });
});
Adds custom headers to the response.
Supabase Edge Function Fetching External API
# supabase/demo/fetch.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve(async (_req) => {
const res = await fetch('https://api.github.com');
const data = await res.json();
return new Response(JSON.stringify(data), { status: 200, headers: { 'Content-Type': 'application/json' } });
});
Fetches data from an external API and returns it.
Supabase Edge Function Using Environment Variable
# supabase/demo/env.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((_req) => {
const apiKey = Deno.env.get('MY_API_KEY') || 'NotSet';
return new Response(`API Key length: ${apiKey.length}`, { status: 200 });
});
Uses environment variables in the function.
Supabase Edge Function Conditional Response
# supabase/demo/conditional.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((req) => {
const url = new URL(req.url);
if (url.searchParams.get('action') === 'ping') {
return new Response('pong', { status: 200 });
}
return new Response('unknown action', { status: 200 });
});
Responds differently based on query parameter.
Supabase Edge Function Redirect
# supabase/demo/redirect.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
serve((_req) => {
return new Response(null, { status: 302, headers: { Location: 'https://example.com' } });
});
Redirects to another URL.
Frequently Asked Questions about Supabase-edge-functions
What is Supabase-edge-functions?
Supabase Edge Functions are serverless functions deployed at the edge using Deno runtime, enabling developers to run backend logic close to users with low latency.
What are the primary use cases for Supabase-edge-functions?
RESTful API endpoints for Supabase apps. Custom authentication or authorization flows. Processing webhooks and events. Serverless business logic triggered by frontend requests. Realtime event handling and notifications
What are the strengths of Supabase-edge-functions?
Ultra-low latency for global users. Integrated seamlessly with Supabase backend. Serverless - no server provisioning required. Supports modern TypeScript/JavaScript. Easy to deploy and scale automatically
What are the limitations of Supabase-edge-functions?
Execution time is limited (short-lived requests). Vendor lock-in to Supabase platform. Cold starts may affect first requests. Limited runtime compared to full server environments. Debugging and monitoring require Supabase tooling
How can I practice Supabase-edge-functions typing speed?
CodeSpeedTest offers 10+ real Supabase-edge-functions code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.