Svelte and SvelteKit 5 · SvelteKit

Create an API endpoint

A +server.ts file exports a function per HTTP method.

// src/routes/api/hello/+server.ts
import { json } from "@sveltejs/kit";

export function GET() {
  return json({ message: "Hello" });
}

Official Svelte and SvelteKit 5 documentation

More sveltekit commands

All sveltekit commands · Svelte and SvelteKit 5 cheatsheet

Was this page helpful?