mirror of
https://github.com/cupcakearmy/koa-parser.git
synced 2024-12-22 08:06:30 +00:00
Koa Body Parser Middleware
LICENSE | ||
package.json | ||
Parser.js | ||
README.md |
Koa Body Parser
Koa-Middleware for parsing body parameters in the request. Lightweight and no dependencies.
Install
npm install cca-koa-parser --save
QA
If you have questions:
Supported encodings:
- form-data
- x-www-form-urlencoded
- json
Complete Example
const
Koa = require('koa'),
parser = require('cca-koa-parser'),
router = require('cca-koa-router')
const
app = new Koa(),
port = 3000
app.use(parser)
app.use(router(_ => {
_.post('/', (c, n) => {
c.body = c.request.body
})
}))
app.listen(port)
Documentation
~ body
Element
The Parser defines an object ctx.request.body
where all the sent parameters are stored
Example
// Request: HTTP POST /
ctx.request.body['username'] => "joe"