1.0.1 • Published 5 years ago

@hattmo/ajvmiddleware v1.0.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
5 years ago

AJVMIDDLEWARE

About

Middleware for express that validates json bodies in requests using ajv

Installation

npm i @hattmo/ajvmiddleware

Example

import { Router } from "express";
import ajvmiddleware from "@hattmo/ajvmiddleware";

const schema = {
  $schema: "http://json-schema.org/draft-07/schema#",
  type: "object",
  required: [
    "name",
    "age",
  ],
  properties: {
    name: {
      type: "string",
    },
    age: {
      type: "integer",
    },
  },
};

const route = Router();

route.post("/submit", ajvmiddleware(schema), (req, _res, next) => {
  console.log(`${req.body.name} is ${req.body.age} years old`);
  next()
});

export default route;

Author

Designed and maintained by Matthew Howard.

Support me with a donation!

1.0.1

5 years ago

1.0.0

5 years ago