What are Edge Functions
Edge Functions are small pieces of code that run on the server instead of in the browser. They’re useful for things you can’t (or shouldn’t) do in the browser:- Payment processing - Connect to Stripe, PayPal, or other payment providers
- Sending emails - Send confirmation emails, notifications, or newsletters
- API integrations - Connect to external services like HubSpot, Zendesk, or custom APIs
- Protected operations - Tasks that need secret API keys you don’t want exposed
Creating Functions with OptiDev Agent
The easiest way to create Edge Functions is to describe what you need to OptiDev Agent.Example: Stripe Payment
“Create an API endpoint that accepts credit card payments with Stripe. It should take the amount and save the order to the database”OptiDev Agent will:
- Create the Edge Function with Stripe integration
- Handle the payment processing securely
- Save order details to your database
- Deploy it to OptiDev Cloud
Example: Email Notifications
“Create a function that sends a welcome email when a new user signs up”OptiDev Agent will:
- Set up email sending (using a service like Resend or SendGrid)
- Create a nicely formatted welcome email template
- Connect it to your user registration flow
Example: External API Integration
“Create an endpoint that fetches customer data from our HubSpot account when given a customer email”OptiDev Agent will:
- Create the function with HubSpot API integration
- Handle authentication with your HubSpot API key
- Return the customer data in a clean format
Viewing Functions in the Dashboard
The Edge Functions Tab
Go to the Edge Functions tab in OptiDev Cloud to see:- Overview card - Shows how many functions are in your workspace and how many are deployed
- Workspace Functions - Functions in your project files, ready to deploy
- Deployed Functions - Functions currently running on OptiDev Cloud
Function Status Indicators
Each function shows its current status:| Indicator | Meaning |
|---|---|
| Green checkmark with “Deployed” | Running on OptiDev Cloud |
| Orange warning with “Not deployed” | In your workspace but not yet deployed |
| ”Needs deployment” count | Functions that have changed since last deploy |
Deploying Functions
From the Dashboard
- Go to the Edge Functions tab
- Find your function under Workspace Functions
- Click Deploy (or Redeploy if updating)
With OptiDev Agent
Just ask OptiDev Agent to deploy:“Deploy my payment function”Or deploy all functions at once:
“Deploy all my Edge Functions”
Automatic Deployment
When you ask OptiDev Agent to create a function, it typically deploys automatically after creating the code.Testing Functions
Before connecting a function to your app, test it directly from the dashboard.Opening the Test Panel
- Find your function under Deployed Functions
- Click the Test button
Making a Test Request
The test panel lets you configure:- HTTP Method - GET, POST, PUT, DELETE, or PATCH
- Request Body - JSON data to send (for POST/PUT requests)
- Headers - Any custom headers your function expects
- Query Parameters - URL parameters like
?name=John
Running the Test
- Configure your request
- Click Send Request
- See the response including:
- Status code (200 = success, 400/500 = error)
- Response data
- Response time
Example Test
For a payment function, you might test with:- Method: POST
- Body:
{ "amount": 2500, "currency": "usd" }
Viewing Function Details
Click View Details on any deployed function to see:Function URL
The web address for calling your function. This is what your app uses to communicate with the function. Click Copy URL to copy it to your clipboard.Execution Information
- Version - The current deployed version number
- Last updated - When the function was last deployed
- Status - Whether the function is active
Managing Functions
Updating a Function
When you modify a function’s code:- The function appears with a “needs deployment” indicator
- Click Redeploy to push the changes
- The new version goes live immediately
Deleting a Function
- Click the trash icon next to the deployed function
- Confirm the deletion
Getting the Function URL
Every deployed function has a unique URL. To use it in your app:- Find the function under Deployed Functions
- Click Copy URL
- Use this URL in your app to call the function
Creating Your First Function
If you don’t have any functions yet, the dashboard shows a helpful empty state.Quick Start with Sample Function
Click Create Sample Function to generate a simple “hello world” function. This gives you:- A working function you can deploy immediately
- Example code structure to learn from
- A starting point to modify for your needs
With OptiDev Agent
Describe what you need:“Create a simple API endpoint that returns the current date and time”OptiDev Agent will create the function, explain the code, and deploy it for you.
Common Use Cases
Webhook Handlers
“Create a function that receives webhooks from Stripe and updates order status in the database”
Form Submissions
“Create an endpoint that receives contact form submissions and sends them to my email”
Data Processing
“Create a function that takes a CSV file and imports the data into my products table”
Scheduled Tasks
“Create a function that runs daily to send reminder emails for upcoming appointments”
Third-Party Integrations
“Create a function that syncs new customers to my Mailchimp mailing list”
Secrets and API Keys
Many integrations require API keys (like your Stripe secret key). These should never be in your frontend code.Managing Secrets
Go to the Secrets tab in OptiDev Cloud:- Click Add Secret
- Enter a name (like
STRIPE_SECRET_KEY) - Enter the value (your actual API key)
- Click Save
Using Secrets in Functions
Ask OptiDev Agent to use your secrets:“Create a Stripe payment function using my STRIPE_SECRET_KEY secret”OptiDev Agent will write code that securely accesses your secret.
Secrets are write-only for security. You can create and delete them, but you can’t view the values after saving.
For Developers
Technical Reference
Technical Reference
Function Structure
Edge Functions are TypeScript/JavaScript files that run on Deno. Each function lives in:Accessing Secrets
In your function code, access secrets with:CORS Handling
Functions need to handle CORS for browser requests. The sample function includes proper CORS headers.Function URL Format
Invoking from Your App
The Supabase client can call functions directly:Logging
Useconsole.log() in your functions. Logs are viewable in the function details panel.