I have a simple Node JS application, that allows a request to be send to my Node API through POSTMAN. This is what the request looks like (the request must be XML):
<?xml version="1.0" encoding="UTF-8"?>
<myOrders>
<myOrderData>
<people>5</people>
<language>5</language>
<customers>
<customer_id>15</customer_id>
</customers>
</myOrderData>
</myOrders>
In my Node JS program, so far I dont do anything with the request as I need to validate that the above request contains the following fields : myOrders, myOrderData, people, language, customers, customer_id
router.post('/myorder', function(req, res, next) {
console.log('body testing', req.body)
}
The above prints out: { myorders: { myorderdata: [ [Object] ] } }
Is there a way I can validate this before continuing, and throwing an error if the above fields are not present in the request? Any help will be appreciated.
Note: validation needs to happen within the node js API call, not anywhere else
via deeveeABC
No comments:
Post a Comment