Parsed body equals raw body
demisx opened this issue · comments
Dmitri commented
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:
- What's the purpose of this bodyparser when the
content-type': 'text/plain'
? What exactly it's supposed to do? - 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
Yiyu He commented
bodyparser will treat content-type': 'text/plain'
as plain text and only try to get the request body and parse it to string.
Dmitri commented
Got it. Looks like I do need to parse a text payload to JSON myself. Thank you.