Returning JSON Responses
Use the json() helper to return structured JSON with the correct content-type.
The json Helper
Use json() from @sveltejs/kit to return JSON with proper headers.
import { json } from "@sveltejs/kit";
return json({ ok: true });Status Codes
Pass a second options object to control status and additional headers.
return json({ ok: false }, { status: 400 });All lessons in this course
- +server.js: GET POST PUT DELETE
- Request and RequestEvent
- Returning JSON Responses
- Streaming with ReadableStream