Is it possible to return json body in "+page.server.js" #6067
-
Goal is to return a json response from POST action "+page.server.js". I tried returning body like this, but did not work export async function POST({ request }) {
return {
status: 204,
body: {
content: "some-content"
}
};
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
According to the migration guide:
I'm in the middle of migrating myself so someone else can correct me if I'm wrong but in my app I have // ~/your-endpoint.json/+server.js
import { json } from '@sveltejs/kit';
export async function POST({ request }) {
return json({
content: "some-content"
});
}
return new Response(JSON.stringify({ content: "some-content" }), {
headers: {
'Content-Type': 'application/json'
},
status: 204
}); I say "I think" because I actually get a 500 error when I set the status to
|
Beta Was this translation helpful? Give feedback.
According to the migration guide:
I'm in the middle of migrating myself so someone else can correct me if I'm wrong but in my app I have
/my-endpoint.json/+server.js
and I submitPOST
requests to/my-endpoint.json
getting aResponse
, in your case it would be something like: