The type validator middleware using unknownutil for Hono applications. You can write a schema with unknownutil and check the type of the incoming values.
import { is } from '@core/unknownutil'
import { Hono } from '@hono/hono'
import { uValidator } from '@ryoppippi/hono-unknownutil-validator'
const schema = is.ObjectOf({
name: is.String,
age: is.Number,
})
const app = new Hono()
app.post('/author', uValidator('json', schema), (c) => {
const data = c.req.valid('json')
return c.json({
success: true,
message: `${data.name} is ${data.age}`,
})
})Hook:
app.post(
'/post',
uValidator('json', schema, (result, c) => {
if (result.error) {
return c.text('Invalid!', 400)
}
})
//...
)Ryotaro "Justin" Kimura https://github.com/ryoppippi
MIT