h3-typebox
Install
# Using npm
npm install h3-typebox
# Using yarn
yarn install h3-typebox
# Using pnpm
pnpm install h3-typebox
Usage
import { createServer } from 'http'
import { createApp } from 'h3'
import { useValidatedBody, useValidatedQuery, Type } from 'h3-typebox'
const app = createApp()
app.use('/', async (req) => {
// Validate body
const body = await useValidatedBody(req, Type.Object({
optional: Type.Optional(Type.String()),
required: Type.Boolean(),
}))
// Validate query
const query = useValidatedQuery(req, Type.Object({
required: Type.String(),
}))
})
createServer(app).listen(process.env.PORT || 3000)
See how to define your schema with Type
on TypeBox documentation.
💻
Development - Clone this repository
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
License
Made with
Published under MIT License.