Next.js Discord

Discord Forum

NextJS form handling

Answered
Daggertooth pike conger posted this in #help-forum
Open in Discord
Daggertooth pike congerOP
Hello i am making a form handler using api routes but when i send the body to that POST route i cant read the req.body property how can i solve it?

Here is what it returns when logging it:
ReadableStream { locked: true, state: 'closed', supportsBYOB: false }

I am using react-hook-form, zod and ui mantine.

Thank You
Answered by Daggertooth pike conger
the error was i was doing /api/discord/send
View full answer

10 Replies

You can see here how you can access the body: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#request-body

export async function POST(request: Request) {
  const res = await request.json()
  return Response.json({ res })
}
Daggertooth pike congerOP
Alr thanks so much it was another error
Daggertooth pike congerOP
the error was i was doing /api/discord/send
Answer
Daggertooth pike congerOP
not the full path
ah ok
Daggertooth pike congerOP
yea i just found out after like 2 to 3 hours
and some tabs
ah nice. You might want to mark an answer as answer ^^
Daggertooth pike congerOP
how can i do that?