1.0.0 • Published 6 years ago

express-body-schema v1.0.0

Weekly downloads
2
License
ISC
Repository
-
Last release
6 years ago

Schema Example

const mySchema = {
  "properties": {
    "userId": { "type": "id" },
    "lastName": { "type": "non-empty-string" },
    "firstName": { "type": "string" },
    "email": { "type": "email" },
    "age": { "type": "number" }
  },
  "required": ["userId", "lastName"]
}

Usage with express

const validate = require("express-body-schema");

...
router("/my/route/", validate.schema(mySchema));
...

router("/my/route/", (error, req, res, next) => {

  if (error instanceOf SchemaValidationError) {
    //you can handle the error here
  }

});

...