@longjs/body-parser
Introduction
The module based on @longjs/core, used for HTTP parser body.
Use
> yarn add @longjs/body-parser
or
> npm install @longjs/body-parser
Examples
import Server from '@longjs/core'
import BodyParser from '@longjs/body-parser'
new Server({
port: 3000,
plugins: [
new BodyParser({
multipart: true,
jsonLimit: 1,
formLimit: 56,
textLimit: 56,
text: true,
json: true,
encoding: 'utf-8',
urlencoded: true,
jsonStrict: true,
strict: true,
formidable: {
maxFields: 1000,
maxFieldsSize: 2,
keepExtensions: false,
multiples: true
}
})
]
})
Api
Options
-
jsonLimit
{String|Integer} The byte (if integer) limit of the JSON body, default1mb
-
formLimit
{String|Integer} The byte (if integer) limit of the form body, default56kb
-
textLimit
{String|Integer} The byte (if integer) limit of the text body, default56kb
-
encoding
{String} Sets encoding for incoming form fields, defaultutf-8
-
multipart
{Boolean} Parse multipart bodies, defaultfalse
-
urlencoded
{Boolean} Parse urlencoded bodies, defaulttrue
-
text
{Boolean} Parse text bodies, defaulttrue
-
json
{Boolean} Parse json bodies, defaulttrue
-
jsonStrict
{Boolean} Toggles co-body strict mode; if set to true - only parses arrays or objects, defaulttrue
-
formidable
{Object} Options to pass to the formidable multipart parser -
onError
{Function} Custom error handle, if throw an error, you can customize the response - onError(error, context), default will throw -
strict
{Boolean} If enabled, don't parse GET, HEAD, DELETE requests, defaulttrue