Validation
The purpose of creating an API server is to take an input and process it.
JavaScript allows any data to be of any type. Elysia provides a tool to validate data out of the box to ensure that the data is in the correct format.
import { Elysia, t } from 'elysia'
new Elysia()
.get('/id/:id', ({ params }) => ({
params: t.Object({
id: t.Number()
})
}))
.listen(3000)
TypeBox
Elysia.t is a schema builder based on TypeBox that provides type‑safety at runtime, compile‑time, and OpenAPI schema generation from a single source of truth.
Elysia tailors TypeBox for server‑side validation for a seamless experience.
Standard Schema
Elysia also supports Standard Schema, allowing you to use your favorite validation library:
- Zod
- Valibot
- ArkType
- Effect Schema
- Yup
- Joi
- …and more
To use Standard Schema, simply import the schema and provide it to the route handler.
import { Elysia } from 'elysia'
import { z } from 'zod'
import * as v from 'valibot'
new Elysia()
.get('/id/:id', ({ params, query }) => ({
params: z.object({
id: z.number()
}),
query: v.object({
name: v.string()
})
}))