rsnext/examples/with-joi/pages/api/people.js
Sergio bace9b4949
Add with-joi example (#25759)
* 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>
2021-08-02 19:43:07 -05:00

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 })
})