0
0
Supabasecloud~10 mins

Invoking Edge Functions from client in Supabase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Invoking Edge Functions from client
Client triggers function call
Send HTTP request to Edge Function URL
Edge Function receives request
Edge Function processes logic
Edge Function sends response
Client receives response and handles it
The client sends a request to the Edge Function URL, the function runs its logic, then returns a response back to the client.
Execution Sample
Supabase
const { data, error } = await supabase.functions.invoke('hello');
if (error) console.error(error);
else console.log(data.message);
Client calls the Edge Function named 'hello' and logs the response or error.
Process Table
StepActionRequest StatusResponse DataClient Output
1Invoke 'hello' Edge FunctionRequest sentN/AWaiting for response
2Edge Function receives requestProcessingN/AWaiting for response
3Edge Function runs logicProcessing{"message":"Hello from Edge!"}Waiting for response
4Edge Function sends responseCompleted{"message":"Hello from Edge!"}Waiting for response
5Client receives responseCompleted{"message":"Hello from Edge!"}Logs: Hello from Edge!
6EndN/AN/AProcess complete
💡 Client received response and logged the message, ending the invocation process.
Status Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
dataundefinedundefinedundefined{"message":"Hello from Edge!"}{"message":"Hello from Edge!"}
errorundefinedundefinedundefinedundefinedundefined
Key Moments - 2 Insights
Why does the client wait after sending the request before logging the data?
Because the request is asynchronous, the client must wait for the Edge Function to process and respond before data is available, as shown between steps 1 and 5 in the execution table.
What happens if the Edge Function returns an error?
The error variable will be set and the client can handle it, for example by logging it. This is implied in the sample code where error is checked after invocation.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the client output at step 5?
ALogs: Hello from Edge!
BWaiting for response
CRequest sent
DProcess complete
💡 Hint
Check the 'Client Output' column at step 5 in the execution table.
At which step does the Edge Function send its response back to the client?
AStep 2
BStep 5
CStep 4
DStep 3
💡 Hint
Look at the 'Action' and 'Request Status' columns to find when the response is sent.
If the Edge Function returned an error, which variable would hold that information?
Aresponse
Berror
Cdata
Dstatus
💡 Hint
Refer to the variable_tracker where 'error' is used to capture issues.
Concept Snapshot
Invoke Edge Functions from client using supabase.functions.invoke('functionName').
The call sends a request to the Edge Function URL.
The function runs and returns a response.
Client awaits response asynchronously.
Handle errors by checking the error variable.
Use the returned data as needed.
Full Transcript
This visual execution shows how a client calls a Supabase Edge Function named 'hello'. The client sends a request asynchronously and waits. The Edge Function receives the request, runs its logic, and sends back a JSON response with a message. The client receives this response and logs the message. Variables 'data' and 'error' track the response and any errors. Key moments include understanding asynchronous waiting and error handling. The quiz tests knowledge of client output timing, response sending step, and error variable usage.