* feat(typia-validator): upgrade typia dependency to ^6.1.0 This commit updates the peer dependency of typia from ^5.0.4 to ^6.1.0 in the typia-validator package. The yarn.lock file has also been updated to reflect this change. * feat(typia-validator): update Typia peerDependency The peerDependency of Typia in '@hono/typia-validator' has been updated from version 5 to version 6. |
||
---|---|---|
.. | ||
src | ||
test | ||
CHANGELOG.md | ||
README.md | ||
jest.config.js | ||
package.json | ||
tsconfig.cjs.json | ||
tsconfig.esm.json | ||
tsconfig.json |
README.md
Typia validator middleware for Hono
The validator middleware using Typia for Hono applications.
Usage
import typia, { tags } from 'typia'
import { typiaValidator } from '@hono/typia-validator'
interface Author {
name: string
age: number & tags.Type<'uint32'> & tags.Minimum<20> & tags.ExclusiveMaximum<100>
}
const validate = typia.createValidate<Author>()
const route = app.post('/author', typiaValidator('json', validate), (c) => {
const data = c.req.valid('json')
return c.json({
success: true,
message: `${data.name} is ${data.age}`,
})
})
Hook:
app.post(
'/post',
typiaValidator('json', validate, (result, c) => {
if (!result.success) {
return c.text('Invalid!', 400)
}
})
//...
)
Author
Patryk Dwórznik https://github.com/dworznik
License
MIT