Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.

FlorianWendelborn/spirit-body

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

See Also

License

MIT