Challenge - 5 Problems
SvelteKit HTTP Handlers Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the output of this Svelte GET handler?
Consider this SvelteKit GET handler code. What JSON response will the client receive?
Svelte
export async function GET() { return new Response(JSON.stringify({ message: 'Hello from GET' }), { headers: { 'Content-Type': 'application/json' } }); }
Attempts:
2 left
💡 Hint
Look at the returned JSON string inside the Response.
✗ Incorrect
The GET handler returns a JSON response with the message 'Hello from GET'.
❓ state_output
intermediate1:30remaining
What happens after this POST handler runs?
This SvelteKit POST handler receives JSON data and returns a modified response. What is the output JSON?
Svelte
export async function POST({ request }) { const data = await request.json(); return new Response(JSON.stringify({ received: data.text.toUpperCase() }), { headers: { 'Content-Type': 'application/json' } }); }
Attempts:
2 left
💡 Hint
The handler converts the 'text' field to uppercase.
✗ Incorrect
The POST handler reads JSON, converts 'text' to uppercase, and returns it under 'received'.
📝 Syntax
advanced2:00remaining
Which PUT handler code is syntactically correct?
Choose the correct SvelteKit PUT handler syntax that updates a resource and returns status 204.
Attempts:
2 left
💡 Hint
Check for correct parameter destructuring and await usage.
✗ Incorrect
Option C correctly destructures the parameter, awaits JSON parsing, and returns Response with status 204.
🔧 Debug
advanced2:00remaining
Why does this DELETE handler cause a runtime error?
This SvelteKit DELETE handler throws an error. Identify the cause.
Svelte
export async function DELETE({ params }) { const id = params.id; if (!id) { return new Response('Missing ID', { status: 400 }); } await database.delete(id); return new Response(null, { status: 204 }); }
Attempts:
2 left
💡 Hint
Check if params is available in the handler context.
✗ Incorrect
If the route does not define an [id] parameter, params.id is undefined causing errors.
🧠 Conceptual
expert1:30remaining
Which HTTP method handler should you use to partially update a resource in SvelteKit?
You want to update only some fields of a resource without replacing it entirely. Which handler method is best practice?
Attempts:
2 left
💡 Hint
Consider HTTP methods semantics for partial updates.
✗ Incorrect
PATCH is the HTTP method designed for partial updates of resources.