Koa Body Parser Middleware
Go to file
The Gitter Badger a6a21970ed Add Gitter badge
2017-10-27 12:55:09 +00:00
LICENSE Initial commit 2017-08-18 18:53:06 +02:00
package.json Changed to cca-koa-router 2017-08-21 00:23:57 +02:00
Parser.js Readme Doc 2017-08-18 19:16:14 +02:00
README.md Add Gitter badge 2017-10-27 12:55:09 +00:00

Koa Body Parser

Join the chat at https://gitter.im/cupcakearmy/koa-parser npm npm npm

Koa-Middleware for parsing body parameters in the request. Lightweight and no dependencies.

Install

npm install cca-koa-parser --save
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"