1.0.2 • Published 7 years ago
@longjs/body-parser v1.0.2
@longjs/body-parser
Introduction
The module based on @longjs/core, used for HTTP parser body.
Use
> yarn add @longjs/body-parseror
> npm install @longjs/body-parserExamples
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, default1mbformLimit{String|Integer} The byte (if integer) limit of the form body, default56kbtextLimit{String|Integer} The byte (if integer) limit of the text body, default56kbencoding{String} Sets encoding for incoming form fields, defaultutf-8multipart{Boolean} Parse multipart bodies, defaultfalseurlencoded{Boolean} Parse urlencoded bodies, defaulttruetext{Boolean} Parse text bodies, defaulttruejson{Boolean} Parse json bodies, defaulttruejsonStrict{Boolean} Toggles co-body strict mode; if set to true - only parses arrays or objects, defaulttrueformidable{Object} Options to pass to the formidable multipart parseronError{Function} Custom error handle, if throw an error, you can customize the response - onError(error, context), default will throwstrict{Boolean} If enabled, don't parse GET, HEAD, DELETE requests, defaulttrue
Issues
Contribution