From 8161eb5ebde3935bd58f934bc8ac62a16b375ad4 Mon Sep 17 00:00:00 2001 From: Santiago Quinteros Date: Sat, 4 May 2019 01:03:00 -0500 Subject: [PATCH] Add docs for celebrate --- README.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1319986..6efa60c 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,41 @@ npm run start ``` It uses nodemon for livereloading :peace-fingers: +# API Validation + + By using celebrate the req.body schema becomes clary defined at route level, so even frontend devs can read what an API endpoint expects without need to writting a documentation that can get outdated quickly. + + ```js + route.post('/signup', + celebrate({ + body: Joi.object({ + name: Joi.string().required(), + email: Joi.string().required(), + password: Joi.string().required(), + }), + }), + controller.signup) + ``` + + **Example error** + + ```json + { + "errors": { + "message": "child \"email\" fails because [\"email\" is required]" + } + } + ``` + +[Read more about celebrate here](https://github.com/arb/celebrate) and [the Joi validation API](https://github.com/hapijs/joi/blob/v15.0.1/API.md) # Roadmap -- [ ] API Validation layer (Celebrate+Joi) +- [x] API Validation layer (Celebrate+Joi) - [ ] Unit tests examples - [ ] [Cluster mode](https://softwareontheroad.com/nodejs-scalability-issues?utm_source=github&utm_medium=readme) - [ ] The logging _'layer'_ - [ ] Add ageda dashboard -- [ ] Continuous integration with CircleCI 😍 +- [x] Continuous integration with CircleCI 😍 - [ ] Deploys script and docs for AWS Elastic Beanstalk and Heroku - [ ] Integration test with newman 😉 - [ ] Instructions on typescript debugging with VSCode