You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A body parser for koa, based on co-body. support json, form and text type body.
基于co-body的 koa body解析器。支撑json,form 和text键入主体。
Notice: this module don't support parsing multipart format data, please use co-busboy to parse multipart format data.
注意:此模块不支持解析多部分格式数据,请使用co-busboy解析多部分格式数据。
(function(log){constKoa=require('koa');constbodyParser=require('koa-bodyparser');constapp=newKoa();app.use(bodyParser());app.use(asyncctx=>{// the parsed body will store in ctx.request.body// if nothing was parsed, body will be an empty object {}ctx.body=ctx.request.body;});})(console.log)
参数说明
参数名
参数说明
enableTypes
parser will only parse when request type hits enableTypes, support json/form/text/xml, default is ['json', 'form'].
encoding
requested encoding. Default is utf-8 by co-body.
formLimit
limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 56kb.
jsonLimit
limit of the json body. Default is 1mb.
textLimit
limit of the text body. Default is 1mb.
xmlLimit
limit of the xml body. Default is 1mb.
strict
when set to true, JSON parser will only accept arrays and objects. Default is true. See strict mode in co-body. In strict mode, ctx.request.body will always be an object(or array), this avoid lots of type judging. But text body will always return string type.
detectJSON
custom json request detect function. Default is null.
extendTypes
support extend types
onerror
support custom error handle, if koa-bodyparser throw an error, you can customize the response like
disableBodyParser
you can dynamic disable body parser by set ctx.disableBodyParser = true.
detectJSON
custom json request detect function. Default is null.
koa-bodyparser
官方仓库
https://github.com/koajs/body-parser
官方
npm
地址https://www.npmjs.com/package/koa-bodyparser
https://npm.runkit.com/koa-bodyparser
基础介绍
A body parser for koa, based on co-body. support json, form and text type body.
基于co-body的 koa body解析器。支撑json,form 和text键入主体。
基础安装
基础使用
参数说明
custom json request detect function. Default is null.
support extend types:
support custom error handle, if koa-bodyparser throw an error, you can customize the response like:
相关网站
The text was updated successfully, but these errors were encountered: