0
0
Supabasecloud~10 mins

Creating Edge Functions with Deno in Supabase - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Deno HTTP server module.

Supabase
import { serve } from "[1]";
Drag options to blanks, or click blank then click option'
Ahttps://deno.land/std@0.177.0/io/util.ts
Bhttps://deno.land/std@0.177.0/fs/mod.ts
Chttps://deno.land/std@0.177.0/path/mod.ts
Dhttps://deno.land/std@0.177.0/http/server.ts
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from the file system or path modules instead of HTTP server.
Using an incorrect version or URL.
2fill in blank
medium

Complete the code to start the Deno server listening on port 8000.

Supabase
serve((req) => new Response("Hello from Edge!"), { port: [1] });
Drag options to blanks, or click blank then click option'
A5000
B8000
C3000
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using ports like 8080 or 3000 which are common but not the example default.
Using string instead of number.
3fill in blank
hard

Fix the error in the response header to set JSON content type.

Supabase
return new Response(JSON.stringify({ message: "Hi" }), { headers: { "Content-Type": [1] } });
Drag options to blanks, or click blank then click option'
A"application/json"
B"text/plain"
C"text/html"
D"application/xml"
Attempts:
3 left
💡 Hint
Common Mistakes
Using text/plain or text/html which are for plain text or HTML content.
Using application/xml which is for XML data.
4fill in blank
hard

Fill both blanks to create a Deno Edge function that responds with a JSON message and status 200.

Supabase
export default async function handler(req) {
  return new Response(JSON.stringify({ message: "[1]" }), { status: [2], headers: { "Content-Type": "application/json" } });
}
Drag options to blanks, or click blank then click option'
AHello from Edge
B404
C200
DError
Attempts:
3 left
💡 Hint
Common Mistakes
Using error messages or wrong status codes like 404.
Forgetting to stringify the JSON.
5fill in blank
hard

Fill all three blanks to create a Deno Edge function that reads a query parameter 'name' and responds with a personalized greeting in JSON.

Supabase
export default async function handler(req) {
  const url = new URL(req.url);
  const name = url.searchParams.get("[1]") || "Guest";
  const body = JSON.stringify({ greeting: `Hello, [2]!` });
  return new Response(body, { status: [3], headers: { "Content-Type": "application/json" } });
}
Drag options to blanks, or click blank then click option'
Ausername
Bname
C200
D404
E${name}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong query parameter keys.
Using incorrect status codes.
Not using the variable inside the greeting.