Next.js Discord

Discord Forum

req.body is undefine in route-handler

Answered
Muhammad Abu Bakar posted this in #help-forum
Open in Discord
route.ts export async function POST(req: Request, res: NextApiResponse) { console.log("Received images: ", req.body); } And form.tsx const res = await fetch("http://localhost:3000/api/foodItem/create", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...data, price: parseFloat(data.price), deliveryCharge: parseFloat(data.deliveryCharge), rating: parseInt(data.rating, 10), images: imagesBase64, }), });

4 Replies