A koa body parser middleware with support for
multipart
,json
,csp-report
orurlencoded
request bodies. Via formidable and co-body.
Install with npm
$ npm install koa-better-body
$ npm test
For a more comprehensive examples, see examples folder.
examples/multer
- usage like Express's bodyParser - multernpm run examples-multer
examples/koa-router
- usage with Alex's koa-routernpm run examples-koa-router
However,
koa-better-body
have few custom options, see also co-body, raw-body, formidable
[options]
{Object}patchNode
{Boolean} Patch request body to Node'sctx.req
object, defaultfalse
patchKoa
{Boolean} Patch request body to Koa'sctx.request
object, defaulttrue
jsonLimit
{String|Number} The byte limit of the JSON body, default1mb
formLimit
{String|Number} The byte limit of the form body, default56kb
encoding
{String} Sets encoding for incoming form fields, defaultutf-8
multipart
{Boolean} Supportmultipart/form-data
request bodies, defaultfalse
fieldsKey
{String|Boolean} Name of the key for fields in the body object orfalse
, default'fields'
formidable
{Object} Options that are passing toformidable
formidable.maxFields
{Number} See formidable-options. our default10
formidable.multiples
{Boolean} See formidable-options, our defaulttrue
formidable.keepExtensions
{Boolean} See formidable-options, our defaulttrue
return
{GeneratorFunction} That you can use with koa or co
See node-formidable for a full list of options
bytesExpected
{Integer} The expected number of bytes in this form, defaultnull
maxFields
{Integer} Limits the number of fields that the querystring parser will decode, default1000
maxFieldsSize
{Integer} Limits the amount of memory a field can allocate in bytes, default2mb
uploadDir
{String} Sets the directory for placing file uploads in, defaultos.tmpDir()
hash
{String} If you want checksums calculated for incoming files -'sha1'
or'md5'
, defaultfalse
multiples
{Boolean} Multiple file uploads or no, defaultfalse
Copyright (c) 2014 Charlike Make Reagent, contributors.
Released under the MIT
license.