Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Destructuring 'req.body.data' into 'req.body'

I am sending some data from the front end to the back end. I am trying to send data as an object to the back. When it arrives, it is obviously req.body.data, but should land in the backend as req.body. How do I destructure the request, either from the front or the back so that the back only receives req.body

front end

const { user } = await axios.post('http://localhost:3000/auth/signup', {data});

Backend (what I want)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if(req.body.type === 'vendor') {

Right now the backend received (What i dont want)

if(req.body.data.type....)

>Solution :

Your passing data as an object prop. Just pass it directly:

const { user } = await axios.post('http://localhost:3000/auth/signup', data)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading