I've setup a simple api route in nextjs and am trying to parse the body for post request data but get "undefined" when I use the syntax console.log(req.body.name)
if I output to the console the request body console.log(req.body)
I get what looks like a plain string:
------WebKitFormBoundaryMJBujN4oNXLxcU96
Content-Disposition: form-data; name="name"
bilbo.com
------WebKitFormBoundaryMJBujN4oNXLxcU96
Content-Disposition: form-data; name="price"
2995
------WebKitFormBoundaryMJBujN4oNXLxcU96--
this is the function:
export default (req, res) => {
console.log(req.method);
console.log(req.body);
console.log(req.body.name);
res.status(200).json( { items: [ { req : req.method } ] } )
}
and the data in the request headers: