Preparing your workspace
Edge Functions provide server-side execution environments for custom backend logic that should not run directly in the browser.
Some operations require trusted server-side code, such as calling third-party APIs with secret keys, processing webhooks, performing secure transformations, or implementing specialized backend logic. Supabase Edge Functions provide a place for this code to run separately from client-side JavaScript. Secrets can be configured in the function environment rather than exposed to browsers. Authentication information can also be verified so functions can enforce application rules.
A learning platform could use an Edge Function to process a payment webhook or call an external service using a secret API key.
Deno.serve(async (req) => {
try {
const body = await req.json();
return new Response(
JSON.stringify({ received: true, body }),
{ headers: { 'Content-Type': 'application/json' } }
);
} catch {
return new Response(
JSON.stringify({ error: 'Invalid request' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
);
}
});The function accepts a request, reads its JSON body, and returns a JSON response.