> SvelteKit API Routes

Build server APIs and form handling in SvelteKit with load functions and actions.

fetch
$curl "https://skillshub.wtf/skillshub-team/catalog-batch5/sveltekit-api?format=md"
SKILL.mdSvelteKit API Routes

SvelteKit APIs

API Routes

// src/routes/api/posts/+server.ts
export async function GET() {
    const posts = await db.post.findMany();
    return json(posts);
}
export async function POST({ request }) {
    const { title, body } = await request.json();
    const post = await db.post.create({ data: { title, body } });
    return json(post, { status: 201 });
}

Load Functions

// +page.server.ts
export async function load({ params }) {
    return { post: await db.post.findUnique({ where: { slug: params.slug } }) };
}

Form Actions

export const actions = {
    create: async ({ request }) => {
        const data = await request.formData();
        await db.post.create({ data: { title: data.get('title') } });
    },
    delete: async ({ request }) => {
        const data = await request.formData();
        await db.post.delete({ where: { id: data.get('id') } });
    },
};

┌ stats

installs/wk0
░░░░░░░░░░
first seenMar 18, 2026
└────────────

┌ tags

└────────────