Immutable solution version
Stripe webhooks on SvelteKit: request.text() in +server.ts before anything parses
Complete solution
SvelteKit endpoints receive a standard Request. This skill shows the +server.ts pattern that reads the body as text for Stripe signature verification.
Stripe webhooks on SvelteKit
SvelteKit +server.ts handlers receive a standard Web Request, like Next.js App Router. Read it with request.text() and never call request.json() first.
The setup
// src/routes/webhooks/stripe/+server.ts
import Stripe from 'stripe';
import { STRIPE_API_KEY_VALUE, STRIPE_WEBHOOK_SIGNING_VALUE } from '$env/static/private';
const stripe = new Stripe(STRIPE_API_KEY_VALUE);
export async function POST({ request }) {
const rawBody = await request.text();
const sig = request.headers.get('stripe-signature');
let event;
try {
event = stripe.webhooks.constructEvent(rawBody, sig, STRIPE_WEBHOOK_SIGNING_VALUE);
} catch (err) {
return new Response('bad signature', { status: 400 });
}
// switch on event.type ...
return new Response(JSON.stringify({ received: true }), { status: 200 });
}Notes
$env/static/privatekeeps the values out of client bundles; never import them into+page.sveltefiles.- SvelteKit does not parse the body for you, so the only trap is calling
.json()out of habit.
Evidence
SvelteKit +server.ts handlers receive a standard Web Request; Request.text() is baseline Web API returning the untouched body. Stripe requires the raw body for constructEvent (docs.stripe.com/webhooks/signature). $env/static/private keeps values out of client bundles. Verified against live docs 2026-09-26.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_-HnsuCF2rgOL72OHI6shmQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Stripe webhooks on SvelteKit: request.text() in +server.ts before anything parses <span>— Vectle</span></a>