can we still post json to an endpoint? #8831
Replies: 6 comments 3 replies
-
If you don't want to use form actions, you can still create a import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
export const POST = (async ({ request }) => {
const { a, b } = await request.json();
return json(a + b);
}) satisfies RequestHandler; |
Beta Was this translation helpful? Give feedback.
-
I was basically doing this in +server.ts
and getting a 500 with no indication that the function was being executed |
Beta Was this translation helpful? Give feedback.
-
still no joy src/routes/api/codebreaker/+server.ts
src/routes/codebreaker/+page.svelte
response
|
Beta Was this translation helpful? Give feedback.
-
this was in console running dev
|
Beta Was this translation helpful? Give feedback.
-
after going down a rabbit hole this is indeed an issue with prisma and a commonjs export |
Beta Was this translation helpful? Give feedback.
-
after installing @originjs/vite-plugin-commonjs I'm now at
time to look at other ORMs |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been looking through both the docs and this forum and can't seem to find the right file structure or syntax to make an enpoint that can have json posted to it with fetch, create a record with prisma, and the return the new record. You know, like an api.
I've been a fan of svelte for a while but I'm a little lost with the new stuff.
Beta Was this translation helpful? Give feedback.
All reactions