A body parser middleware for octoris
npm i @octoris/body-parser
The json parser for handling json payloads
strict
: when set to true, JSON parser will only accept arrays and objects; when false will accept anything JSON.parse accepts. Defaults to true. (also strict mode will always return an object)limit
: Number or string representing the request size limit. Defaults to1mb
encoding
: The content encoding type. Defaults toutf8
const { router, response, methods} = require('octoris')
const { json } = require('@octoris/body-parser')
function handler () {
return new Promise(resolve => send(200, 'Okay!'))
}
const home = router.route([router.fixed('/')], [methods.GET(handler)])
router.composeRoutes({}, [home], [json()])
Form parser for handling url-encoded form payloads
queryString
: An options object that is passed directly to the qs modulelimit
: A number or string representing the request size limit. Defaults to56kb
qs
: The querystring function you'd like to use. Defaults toqs
encoding
: The content encoding type. Defaults toutf8
const { router, response, methods} = require('octoris')
const { form } = require('@octoris/body-parser')
function handler () {
return new Promise(resolve => send(200, 'Okay!'))
}
const home = router.route([router.fixed('/')], [methods.GET(handler)])
router.composeRoutes({}, [home], [form()])