Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielwpz/crepecake-params
Params schema validation middleware for crepecake
https://github.com/danielwpz/crepecake-params
Last synced: 14 days ago
JSON representation
Params schema validation middleware for crepecake
- Host: GitHub
- URL: https://github.com/danielwpz/crepecake-params
- Owner: danielwpz
- Created: 2020-06-14T03:56:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T04:52:54.000Z (almost 2 years ago)
- Last Synced: 2024-10-08T00:55:38.968Z (about 1 month ago)
- Language: TypeScript
- Size: 248 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# crepecake-params
Params schema validation middleware for Crepecake, based on Joi## Introduction
This is a Koa/crepecake middleware which aims to:
1. Provide a unified way for downstream middlewares to retrive request parameters
2. Enable parameter schema validation## Reference
- Joi: https://hapi.dev/module/joi/#introduction## Example
```javascript
const Crepecake = require('crepecake')
const app = new Crepecake()
const params = require('crepecake-params')
const Joi = require('@hapi/joi')
const Router = Crepecake.Router
const route = new Router()const getSchema = Joi.object({
name: Joi.string().required(),
test: Joi.boolean().default(false),
date: Joi.date().required()
})route.get('/', params(getSchema, { abortEarly: false }), async ctx => {
console.log(ctx.state.params)
return ctx.state.params
})app.use(route)
app.listen(8888)
```