0

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?

Nick Parsons
  • 8,377
  • 13
  • 48
  • 70

1 Answers1

1

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;
}
randunel
  • 8,917
  • 1
  • 26
  • 24