我正在尝试使用 .hole 来验证请求的express-validator
主体是单个数组,所以我没有字段名称。
我正在使用版本 4express-validator
的新 API。express
身体是这样的:
["item1","item2"]
我的代码:
app.post('/mars/:Id/Id', [
check('id')
.isLength({ max: 10 })
.body() //try many ways to get the body. most examples i found were for the old api
.custom((item) => Array.isArray(item))
],
(req, res, next) => {
const data: string = matchedData(req); //using this method to only pass validated data to the business layer
return controller.mars(data); //id goes in data.id. i expect there should be an data.body once the body is validated too.
}
我如何验证身体?