Skip to content

e-ucm/express-body-schema

 
 

Repository files navigation

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
  }

});

...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%