spirit-body
Body parser for spirit.
Supports Raw, JSON and URL-encoded bodies.
Usage
Add as spirit middleware:
// tell spirit-body to parse JSONconst jsonBody = // add a spirit routeroute
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