koajs / bodyparser

Koa body parsing middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsed body equals raw body

demisx opened this issue · comments

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

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

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