This package provides a validator middleware using Effect Schema for Hono applications. With this middleware, you can define schemas using Effect Schema and validate incoming data in your Hono routes.
Effect Schema offers several advantages over other validation libraries:
- Bidirectional transformations: Effect Schema can both decode and encode data.
- Integration with Effect: It inherits benefits from the Effect ecosystem, such as dependency tracking in transformations.
- Highly customizable: Users can attach meta-information through annotations.
- Functional programming style: Uses combinators and transformations for schema definition.
import { Hono } from 'hono'
import { Schema as S } from '@effect/schema'
import { effectValidator } from '@hono/effect-validator'
const app = new Hono()
const User = S.Struct({
name: S.String,
age: S.Number,
})
app.post('/user', effectValidator('json', User), (c) => {
const user = c.req.valid('json')
return c.json({
success: true,
message: `${user.name} is ${user.age}`,
})
})target: The target of validation ('json', 'form', 'query', etc.)schema: An Effect Schema schema
Günther Brunner https://github.com/gunta
MIT