spirit-body
v1.2.2
Published
Body parser for spirit.
Downloads
30
Maintainers
Readme
spirit-body
Body parser for spirit.
Supports Raw, JSON and URL-encoded bodies.
Usage
Add as spirit middleware:
import body from 'spirit-body'
// tell spirit-body to parse JSON
const jsonBody = body({
json: true
})
// add a spirit route
route.wrap(
route.post(
'*',
['body'],
body => `the body is ${JSON.stringify(body)}`
),
[jsonBody]
)
Errors
If body parsing failed spirit-body
will set request.invalidBody
to true
. If options.error
is true spirit-body
will automatically respond with 400 Bad Request
. Otherwise request.body
will be undefined
.
Options
| Name | Description | Values |
|---------------:|:----------------------------------------|:-------------------------------|
| allowEmptyBody | ignores requests without content-length | true
, false
|
| error | enable 400 Bad Request
responses | false
, true
|
| form | enable form-parsing | false
, true
|
| json | enable json-parsing | false
, true
|
| text | enable text-parsing | false
, true
|
| limit | body size limit | 4*1024*1024
, 1024
, ... |
Install
With npm installed, run
npm install --save spirit-body
or use yarn:
yarn add spirit-body