1.0.1 • Published 5 months ago

@blubox/body-parser v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Body Parser Middleware

A middleware for parsing request bodies in various formats, including JSON, raw data, urlencoded, and XML.

Installation

npm install @blubox/body-parser

Usage

const bodyParser, { BodyParserOptions } = require('@blubox/body-parser')

const jsonParser = bodyParser.json()
const rawParser = bodyParser.raw()
const urlencodedParser = bodyParser.urlencoded()
const xmlParser = bodyParser.xml()

// Use the middleware in your application

controller.use(jsonParser)
controller.use(rawParser)
controller.use(urlencodedParser)
controller.use(xmlParser)

Options

  • limit (optional): Set a limit on the request body size. Default is unlimited. Example: { limit: '1mb' }
  • requiredHeaders (optional): Array of headers that must be present in the request. Example: { requiredHeaders: 'Content-Type' }
  • disallowedHeaders (optional): Array of headers that must not be present in the request. Example: { disallowedHeaders: 'Authorization' }
  • strictMode (optional): Enable strict mode to enforce all specified options. Default is false. Example: { strictMode: true }

Size Units

Size limits can be specified using units such as 'kb', 'mb', 'gb', or 'tb'. Example: '1mb', '100kb'.

Middleware Methods

json(opts?: BodyParserOptions)

Parses the request body as JSON.

raw(opts?: BodyParserOptions)

Retrieves the raw request body.

urlencoded(opts?: BodyParserOptions)

Parses the request body as urlencoded data.

xml(opts?: BodyParserOptions)

Parses the request body as XML.

License

MIT

1.0.1

5 months ago

1.0.0

5 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago