https://github.com/sunkuo/joi-router
:basketball: Input & Output validated routing for Express
https://github.com/sunkuo/joi-router
express joi joi-validation
Last synced: 10 months ago
JSON representation
:basketball: Input & Output validated routing for Express
- Host: GitHub
- URL: https://github.com/sunkuo/joi-router
- Owner: sunkuo
- Created: 2017-05-04T14:53:45.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-11T14:50:15.000Z (about 9 years ago)
- Last Synced: 2024-11-25T12:02:08.534Z (over 1 year ago)
- Topics: express, joi, joi-validation
- Language: JavaScript
- Homepage:
- Size: 43.9 KB
- Stars: 18
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# joi-router
:basketball: Input & Output validated routing for Express
[](https://badge.fury.io/js/joi-router) [](https://travis-ci.org/sunkuo/joi-router) [](https://coveralls.io/github/sunkuo/joi-router?branch=master) [](https://opensource.org/licenses/MIT)
## Todo List
- :white_check_mark: Input Validated Routing
- :white_check_mark: Output Validated Routing
- :white_check_mark: Examples to show how to use joi-router
- :white_check_mark: Self-contained Test
- :white_check_mark: Continuous integration
- :white_check_mark: Code coverage
- :ballot_box_with_check: Joi-router to api documents
## How to install
`yarn add joi-router`
## Get Started
### Input Validaiton
```
const express = require('express')
const Joi = require('joi')
require('joi-router')
const app = express()
app.get('/foo', {query: {
userId: Joi.string().alphanum().min(3).max(30).required()
}}, function (req, res, next) {
res.json({
result: 'success'
})
})
```
#### Output Validation
```
app.get('/foo', {
output: {
'200': { content: Joi.string().alphanum().min(3).max(30).required() }
}
}, function (req, res, next) {
res.json({
content: 'Lorem'
})
})
app.listen(3000, () => {
console.log('Server Run!')
})
```
## Node compatibility
NodeJS `>= 6.0` is required.
## Performance
Joi-router only run once to add validation middleware when express start, so it does not make express slow.
## LICENSE
[](https://opensource.org/licenses/MIT)