Server Endpoints in Svelte
From the SvelteKit cheat sheet ยท API Routes ยท verified Jul 2026
Server Endpoints
Creating RESTful API endpoints
javascript
// +server.js
import { json } from '@sveltejs/kit';
export async function GET() {
return json({ message: 'Hello' });
}
export async function POST({ request }) {
const data = await request.json();
return json({ received: data });
}๐ RESTful endpoints with +server.js files
๐ Access to cookies and authentication
๐ Full HTTP method support
โก Automatic error handling and status codes