Package Exports
- next-validations
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (next-validations) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Welcome to next-validations 👋
NextJS API Validations
🏠 Homepage
✨ Demo

Prerequisites
- node >=10
- nextjs >= 9
Install
yarn add next-validationsFeatures
- Support Yup validation
- Support Fastest-Validator validation
- Support Joi validation
- ...
Usage
Validate custom API endpoint with Yup
yarn add yup next-validationsimport { NextApiRequest, NextApiResponse } from 'next';
import { withValidation } from 'next-validations';
import * as yup from 'yup';
const schema = yup.object().shape({
name: yup.string().required(),
});
const validate = withValidation({
schema,
type: 'Yup',
mode: 'query',
});
const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(req.query);
};
export default validate(handler);Validate custom API endpoint with fastest-validator
yarn add fastest-validator next-validationsimport { NextApiRequest, NextApiResponse } from 'next';
import { withValidation } from 'next-validations';
const schema = {
name: { type: 'string', min: 3, max: 255 },
email: { type: 'email' },
age: 'number',
};
const validate = withValidation({
schema,
type: 'FastestValidator',
mode: 'body',
});
const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(req.body);
};
export default validate(handler);Run tests
yarn testAuthor
👤 Huynh Duc Dung
- Website: https://productsway.com/
- Twitter: @jellydn
- Github: @jellydn
Show your support
Give a ⭐️ if this project helped you!

This README was generated with ❤️ by readme-md-generator