honojs-middleware/packages/typia-validator
github-actions[bot] 5a0488a254
Version Packages (#572)
2024-06-14 07:43:49 +09:00
..
src chore: enable `eslint` and remove `denoify` (#300) 2023-12-13 17:22:53 +09:00
test fix: deprecated json response method (#488) 2024-04-30 20:32:15 +09:00
CHANGELOG.md Version Packages (#572) 2024-06-14 07:43:49 +09:00
README.md fix: deprecated json response method (#488) 2024-04-30 20:32:15 +09:00
jest.config.js feat: Add Typia validator (#158) 2023-09-15 22:54:56 +09:00
package.json Version Packages (#572) 2024-06-14 07:43:49 +09:00
tsconfig.cjs.json feat: Add Typia validator (#158) 2023-09-15 22:54:56 +09:00
tsconfig.esm.json feat: Add Typia validator (#158) 2023-09-15 22:54:56 +09:00
tsconfig.json feat: Add Typia validator (#158) 2023-09-15 22:54:56 +09:00

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