Skip to content

octoris/body-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

body-parser

A body parser middleware for octoris

Install

npm i @octoris/body-parser

json(opts)

The json parser for handling json payloads

Options

  • 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 to 1mb
  • encoding: The content encoding type. Defaults to utf8

Usage

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(opts)

Form parser for handling url-encoded form payloads

Options

  • queryString: An options object that is passed directly to the qs module
  • limit: A number or string representing the request size limit. Defaults to 56kb
  • qs: The querystring function you'd like to use. Defaults to qs
  • encoding: The content encoding type. Defaults to utf8

Usage

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()])