koajs / bodyparser

Koa body parsing middleware
MIT License
1.31k stars 116 forks source link

Parsed body equals raw body #97

Closed demisx closed 6 years ago

demisx commented 6 years ago

Hi. I might be misunderstanding the purpose of the bodyparser. I have an AWS SNS topic posting to my endpoint JSON data in typeof string and with 'content-type': 'text/plain; charset=UTF-8'. I get the same string after the bodyparser as in the payload (ctx.request.body === ctx.request.rawBody). Just trying to understand the following:

  1. What's the purpose of this bodyparser when the content-type': 'text/plain'? What exactly it's supposed to do?
  2. Is there a better way to parse the text payload into JSON object instead of me doing JSON.parse(). I can't seem to get the bodyparser do it for me.

Thank you.


node@9.3.0 koa@2.0.43 koa-bodyparser@4.2.0

dead-horse commented 6 years ago

bodyparser will treat content-type': 'text/plain' as plain text and only try to get the request body and parse it to string.

demisx commented 6 years ago

Got it. Looks like I do need to parse a text payload to JSON myself. Thank you.