Let's say I want o get a simple variable posted to a Koa app without using an extension, how would I do it?
Asked
Active
Viewed 4,911 times
4
-
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 Answers
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