bace9b4949
* Add joi and next-joi example * Add more README information * Update examples/with-joi/package.json Co-authored-by: Lee Robinson <me@leerob.io> * Update all dependencies to latest Co-authored-by: Lee Robinson <me@leerob.io>
14 lines
384 B
JavaScript
14 lines
384 B
JavaScript
import Joi from 'joi'
|
|
import connect from 'next-connect'
|
|
import { validate } from '../../server/api/middlewares/validate'
|
|
|
|
const personSchema = Joi.object({
|
|
age: Joi.number().required(),
|
|
name: Joi.string().required(),
|
|
})
|
|
|
|
export default connect().post(validate({ body: personSchema }), (req, res) => {
|
|
const person = req.body
|
|
|
|
return res.status(201).json({ data: person })
|
|
})
|