Complete the code to create a SvelteKit page component that exports a load function.
export const load = async () => {
return { message: 'Hello from [1]!' };
};The load function runs on the server in SvelteKit, enabling full-stack routing.
Complete the code to define a SvelteKit endpoint that handles GET requests.
export async function [1]() { return { status: 200, body: { message: 'Hello from API!' } }; }
The GET function handles GET requests in SvelteKit endpoints.
Fix the error in the SvelteKit route file to correctly export the POST handler.
export async function [1](request) { const data = await request.json(); return { status: 201, body: { received: data } }; }
The POST handler must be exported as POST to handle POST requests in SvelteKit.
Fill both blanks to create a SvelteKit page that fetches data from an endpoint and displays it.
<script> import { onMount } from 'svelte'; let message = ''; onMount(async () => { const res = await fetch('/api/message'); const data = await res.[1](); message = data.[2]; }); </script> <p>{message}</p>
Use json() to parse the response and access the message property from the data.
Fill all three blanks to define a SvelteKit endpoint that handles POST requests and returns JSON.
export async function [1](request) { const data = await request.[2](); return { status: 200, headers: { 'Content-Type': '[3]' }, body: { success: true, received: data } }; }
The POST handler uses request.json() to parse JSON data and returns a JSON response with the correct content type.