4

Let's say I want o get a simple variable posted to a Koa app without using an extension, how would I do it?

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • Within middleware/handler, `this.request` gives you access to the Koa request. But `this.req` gives you access to the underlying raw Node request which has all the information you need. You generally use middleware to parse `this.req`, format it, and move it into `this.request` for consumption by your app. So check out the plain ol `this.req`. – danneu Jun 25 '14 at 07:39

1 Answers1

4

You have to use the official koa-bodyparser module.

Then all the POST parameters will be available in this.request.body.


From the docs:

app.use(function *() {
  // the parsed body will store in this.request.body
  // if nothing was parsed, body will be an empty object {}
  this.body = this.request.body;
});
eightyfive
  • 4,601
  • 3
  • 35
  • 44