1.2.2 • Published 7 years ago

spirit-body v1.2.2

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

spirit-body

Body parser for spirit.

Supports Raw, JSON and URL-encoded bodies.

Slack Build Status Coverage Status NPM Downloads NPM Dependencies

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

NameDescriptionValues
allowEmptyBodyignores requests without content-lengthtrue, false
errorenable 400 Bad Request responsesfalse, true
formenable form-parsingfalse, true
jsonenable json-parsingfalse, true
textenable text-parsingfalse, true
limitbody size limit4*1024*1024, 1024, ...

Install

With npm installed, run

npm install --save spirit-body

or use yarn:

yarn add spirit-body

See Also

License

MIT

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

8 years ago