Complete the code to return a JSON response with a message.
import { json } from '@sveltejs/kit'; export function GET() { return [1]({ message: 'Hello from SvelteKit!' }); }
The json helper creates a JSON response with the given data.
Complete the code to return a 404 error with a message.
import { error } from '@sveltejs/kit'; export function GET() { throw [1](404, 'Not found'); }
The error helper throws an HTTP error with a status code and message.
Fix the error in the code to correctly return a JSON response with status 201.
import { json } from '@sveltejs/kit'; export function POST() { return [1]({ success: true }, { status: 201 }); }
The json helper accepts data and an optional options object including status.
Fill both blanks to throw a 401 unauthorized error with a message.
import { [1], json } from '@sveltejs/kit'; export function GET() { throw [2](401, 'Unauthorized access'); }
The error helper is imported and used to throw HTTP errors with status and message.
Fill all three blanks to return a JSON response with a custom header and status 202.
import { json } from '@sveltejs/kit'; export function POST() { return [1]( { message: 'Accepted' }, { status: [2], headers: { 'X-Custom-Header': [3] } } ); }
Use json to return JSON data with status 202 and a custom header string.
