express-validator
https://github.com/ctavan/express-validator
installtion
|
|
joi
Introduction
This is joi, joi allows you to create blueprints or schemas for JavaScript objects (an object that stores information) to ensure validation of key information.
Example
|
|
Install
|
|
本例采用joi,对 schema 的校验。
主要代码
helpers/routerHelpers.js
学完lesson11,发现一个问题 ,idSchema ,使用 param 做key,可以用来校验通用的id,在validateParam中做相应调整。
修改如下: ( 详情,参考 lesson11)
由于代码已经打了tag,不方便修改,旧代码如下:
routers/users.js
controllers/users.js
代码
https://github.com/monk8/expressjs-rest-api-server/tree/lesson08