How to pass json data in request body to nextjs 14 app on start
Unanswered
Asiatic Lion posted this in #help-forum
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?
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",
},