0
0
Supabasecloud~20 mins

Calling external APIs from Edge Functions in Supabase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Edge API Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What is the output when an Edge Function calls an external API and the API returns a 404 status?
Consider an Edge Function that fetches data from an external API endpoint which does not exist, resulting in a 404 HTTP status. What will the Edge Function's fetch call return?
Supabase
export async function handler(request) {
  const response = await fetch('https://api.example.com/nonexistent');
  return new Response(JSON.stringify({ status: response.status }), { status: 200 });
}
A{"status":200}
B{"status":500}
CThrows a network error
D{"status":404}
Attempts:
2 left
💡 Hint
Think about how fetch handles HTTP errors like 404.
Architecture
intermediate
2:00remaining
Which architecture best supports calling multiple external APIs in parallel from an Edge Function?
You want to call three different external APIs from a Supabase Edge Function and combine their results. Which approach is best to minimize total response time?
AUse Promise.all to call all APIs in parallel and await their combined results.
BCall each API sequentially using await one after another.
CCall the first API, then call the second and third APIs in parallel after the first finishes.
DCall only the fastest API and ignore the others.
Attempts:
2 left
💡 Hint
Think about how to run multiple async calls at the same time.
security
advanced
2:00remaining
What is the safest way to store and use API keys when calling external APIs from Supabase Edge Functions?
You need to call an external API that requires an API key. How should you handle the API key in your Edge Function to keep it secure?
AHardcode the API key directly in the Edge Function source code.
BSend the API key from the client to the Edge Function in each request.
CStore the API key in Supabase environment variables and access it inside the Edge Function.
DInclude the API key in the URL query parameters in the Edge Function.
Attempts:
2 left
💡 Hint
Think about where sensitive data should be stored to avoid exposure.
Configuration
advanced
2:00remaining
Which code snippet correctly handles JSON response parsing and errors when calling an external API from an Edge Function?
Choose the code snippet that safely fetches JSON data from an external API and handles possible errors without crashing.
A
const res = await fetch(url);
const data = await res.json();
return new Response(JSON.stringify(data));
B
try {
  const res = await fetch(url);
  if (!res.ok) throw new Error('API error');
  const data = await res.json();
  return new Response(JSON.stringify(data));
} catch (e) {
  return new Response('Error', { status: 500 });
}
C
const res = fetch(url);
const data = await res.json();
return new Response(JSON.stringify(data));
D
const res = await fetch(url);
const data = res.json();
return new Response(JSON.stringify(data));
Attempts:
2 left
💡 Hint
Consider error checking and async handling.
Best Practice
expert
2:00remaining
What is the best practice to avoid cold start delays when calling external APIs from Supabase Edge Functions?
Cold starts can slow down Edge Functions. Which approach helps reduce cold start latency when your function calls external APIs?
AKeep the Edge Function code minimal and use caching for API responses.
BInclude large libraries in the Edge Function to handle all API calls.
CCall external APIs only after a long delay inside the function.
DDeploy multiple versions of the Edge Function with different API keys.
Attempts:
2 left
💡 Hint
Think about what affects startup time and how caching helps.