I'd like to read fetch's body. Here's what I send:
fetch('/api/foo', {
method: 'POST',
body: new FormData(formRef.current),
});
And now I only need to parse the body. But I don't know how. I can't use FormData
on the server side, because it says ReferenceError: FormData is not defined
. And I can't also use forEach
like on the client.
What should I do?
export default function sendMail(req: NextApiRequest, res: NextApiResponse): void {
// console.log(req.body instanceof FormData);
// req.body.forEach(console.log);
console.log(req.body['name']);
res.status(200).json({});
}