I'm running into a brick wall. I need my API to allow for both access via regular form post (application/x-www-form-urlencoded) and JSON (application/json).
If the incoming request is application/json content type, I need to use req.body rather than req.params.
Completely lost on how to accomplish this.
Any thoughts?
One option is adding a conditional statement at the point where you gather the data.
if(req.get('Content-Type') == "application/json") {
data = JSON.parse(req.body);
}
else {
data = req.params;
}