Skip to content

Is it possible to return json body in "+page.server.js" #6067

Answered by fmaclen
Chetan11-dev asked this question in Q&A
Discussion options

You must be logged in to vote

According to the migration guide:

+page.server.js
POST, PUT and PATCH handlers should not return data. They can return an errors object of validation errors that can be used for UI (provided to the component as an errors prop), plus an optional status that defaults to 400 when error is provided and is otherwise ignored...

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 submit POST requests to /my-endpoint.json getting a Response, in your case it would be something like:

// ~/your-endpoint.json/+server.js
import { json } from '@sveltejs/kit';

export async function POST({ request }) {
  return json({

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Chetan11-dev
Comment options

@adonis2611
Comment options

Answer selected by Chetan11-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants