Not every operation should happen directly in the browser. If your application needs server-side logic, Supabase Edge Functions can be useful.
What Should Run on the Server?
Examples include:
Calling third-party APIs Processing webhooks Performing protected operations Handling sensitive credentials Creating custom API endpoints
Create a Function
Create an Edge Function for the specific task your application needs. Keep each function focused rather than putting your entire application into one large function.
Protect Secrets
Sensitive API keys should remain on the server side. Don't expose private credentials inside browser JavaScript.
Call the Function
Your application can send a request to the function when it needs the server-side operation.
Validate Input
Never assume data sent by the browser is trustworthy. Validate the input before performing an action.
Return Useful Responses
Your function should return clear success and error responses. That makes frontend error handling much easier.
Edge Functions can be particularly useful when your application needs small pieces of backend logic without building a separate traditional server.