rsnext/examples/with-joi/pages/api/cars.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

13 lines
324 B
JavaScript

import Joi from 'joi'
import { validate } from '../../server/api/middlewares/validate'
const carSchema = Joi.object({
brand: Joi.string().required(),
model: Joi.string().required(),
})
export default validate({ body: carSchema }, (req, res) => {
const car = req.body
return res.status(201).json({ data: car })
})