Next.js Discord

Discord Forum

How to pass json data in request body to nextjs 14 app on start

Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
I need to start my app with POST request including BODY JSON data. So my app router page should access the request body json object.

This json data will initialize my application accordingly.

I can't find how app router page can access request body. Only params and searchparams. They are not a convenient way to pass object. Do you know how to quickly achieve that?

1 Reply

Northern Inuit Dog
Let's think you collect all of your data in formState. this is the method you can acesss from backend by await request.json();
const response = await fetch("/api/quote", { method: "POST", body: JSON.stringify(formState), headers: { "Content-Type": "application/json", },