我们的原则
设计以人为本
我们的目标是设计一个符合人体工程学、合理且高效的工作框架,即使是初学者也能轻松使用。
设计以避免不必要的复杂性,并为您简化类型复杂性,以便您专注于构建。
一个感觉就像 JavaScript 的框架
import { Elysia, file } from 'elysia'
new Elysia()
.get('/', 'Hello World')
.get('/image', file('mika.webp'))
.get('/stream', function* () {
yield 'Hello'
yield 'World'
})
.ws('/realtime', {
message(ws, message) {
ws.send('got:' + message)
}
})
.listen(3000)21x
比 Express 更快
6x
比 Fastify 更快
Elysia Bun
2,454,631 reqs/sGin Go
676,019
Spring Java
506,087
Fastify Node
415,600
Express Node
113,117
Nest Node
105,064
以每秒请求次数进行测量。数据来源于官方 TechEmpower 基准测试 第 22 轮(2023-10-17)的 PlainText 结果。
It's all about
Single Source of Truth
Schema is the only source of truth for your entire server. From request validation, type inference, OpenAPI documentation, client-server communication. Every part of Elysia is design for complete type integrity.
Request Validation
Elysia validates, and normalize requests against your schema, ensuring that only valid data reaches your handlers.
Elysia also infers types directly from your schema, ensuring that your handlers always receive the correct types in both runtime, and type-level.
import { Elysia, t } from 'elysia'
new Elysia()
.put('/', ({ body: { file } }) => file, {
body: t.Object({
file: t.File({ type: 'image' })
})
})Advance Type Inference
Every part of Elysia is designed to be completely type-safe far more advance type inference than any other frameworks.
Elysia also infers type from your schema, provide an auto-completion for models or extends Elysia with your own custom property all while ensuring complete type integrity.
import { Elysia } from 'elysia'
import { auth } from './auth'
new Elysia()
.use(auth)
.get('/profile', ({ user }) => user, {
auth: true
})import { Elysia, t } from 'elysia'
export const auth = new Elysia()
.macro('auth', {
cookie: t.Object({
ssid: t.String()
}),
resolve({ cookie, status }) {
if(!cookie.ssid.value) return status(401)
return {
user: cookie.ssid.value
}
}
})Client-Server Communication
Elysia can share types between client and server similar to tRPC, ensuring that both sides are always in sync.
Taking a step further, Elysia also handle multiple HTTP status and arrange them using discriminated union, allowing you to handle all possible error cases with ease.
import { treaty } from '@elysiajs/eden'
import type { App } from 'server'
const api = treaty<App>('api.elysiajs.com')
const { data } = await api.profile.patch({
age: 21
})OpenAPI Documentation
Elysia generates OpenAPI documentation from your schema in 1 line. Ensuring your API documentation are always accurate and up-to-date.
import { Elysia } from 'elysia'
import { openapi } from '@elysiajs/openapi'
new Elysia()
.use(openapi())
Introducing our most powerful feature yet
TypeScript to OpenAPI
Elysia can generate OpenAPI specifications directly from your TypeScript code without any annotations, without any configuration and CLI running.
Allowing you to turn your actual code from any library like Prisma, Drizzle and every TypeScript library into your own API documentation.
import { Elysia } from 'elysia'
import { openapi, fromTypes } from '@elysiajs/openapi'
export const app = new Elysia()
.use(
openapi({
// ↓ Where magic happens
references: fromTypes()
})
)Bring your own Validator
With support for Standard Schema
Elysia offers a robust built-in validation, but you can also bring your favorite validator, like Zod, Valibot, ArkType, Effect and more
With seamless support for type inference, and OpenAPI. You will feel right at home .
import { Elysia, t } from 'elysia'
new Elysia()
// Try hover body ↓
.post('/user', ({ body }) => body, {
body: t.Object({
name: t.Literal('SaltyAom'),
age: t.Number(),
friends: t.Array(t.String())
})
})import { Elysia } from 'elysia'
import { z } from 'zod'
new Elysia()
// Try hover body ↓
.post('/user', ({ body }) => body, {
body: z.object({
name: z.literal('SaltyAom'),
age: z.number(),
friends: z.array(z.string())
})
})import { Elysia } from 'elysia'
import * as v from 'valibot'
new Elysia()
// Try hover body ↓
.post('/user', ({ body }) => body, {
body: v.object({
name: v.literal('SaltyAom'),
age: v.number(),
friends: v.array(v.string())
})
})import { Elysia } from 'elysia'
import { type } from 'arktype'
new Elysia()
// Try hover body ↓
.post('/user', ({ body }) => body, {
body: type({
name: '"Elysia"',
age: 'number',
friends: 'string[]'
})
})import { Elysia } from 'elysia'
import { Schema } from 'effect'
new Elysia()
// Try hover body ↓
.post('/user', ({ body }) => body, {
body: Schema.standardSchemaV1(
Schema.Struct({
name: Schema.Literal('Elysia'),
age: Schema.Number,
friends: Schema.Array(Schema.String)
})
)
})11.88ms
POST /character/:id/chat
Playback
对于 DevOps
OpenTelemetry
Elysia 原生支持 OpenTelemetry。监控功能内置,因此您可以轻松监控您的服务,无论平台如何。
import { treaty } from '@elysiajs/eden'
import type { App } from 'server'
const api = treaty<App>('api.elysiajs.com')
const { data } = await api.profile.patch({
age: 21
})对于前端
端到端类型安全
像 tRPC 一样,Elysia 提供从后端到前端的类型安全,而无需代码生成。前端和后端之间的交互在编译时和运行时都经过类型检查。
充满信心地 进行测试
类型安全带有 自动完成功能
Elysia 提供了一个类型安全层,用于与您的服务器进行交互和测试,涵盖从路由到参数的各个环节。
借助自动补全功能,您可以轻松为服务器编写测试,无需任何繁琐操作。
import { treaty } from '@elysiajs/eden'
import { app } from './index'
import { test, expect } from 'bun:test'
const server = treaty(app)
test('应处理重复用户', async () => {
const { error } = await server.user.put({ username: 'mika',
})
expect(error?.value).toEqual({
success: false,
message: '用户名已被占用'
})
})Your code, Your Runtime
Elysia is optimized for Bun,
but not vendor lock-in to Bun
Elysia is built on Web-Standard
allowing you to run Elysia anywhere
人们怎么说
由你实现
Elysia 不属于任何组织 ,由志愿者和社区驱动。 Elysia 的实现得益于这些出色的赞助商。
Thank you for making Elysia possible
We can only develop Elysia full-time thanks to your support.
With love from our community
Got more questions?
Just Ask!Can I use Zod with Elysia?
Elysia validates incoming request data (params, query, body, headers, cookies, response) before your handler runs.
It ships with a built‑in schema builder (Elysia.t) based on TypeBox, but it also natively supports any “Standard Schema” library – that includes Zod, Valibot, Yup, Joi, ArkType, Effect‑Schema, and many more.
Elysia
Ergonomic Framework for Humans
Speed
Top Performance
Type Safety
Best in class
Developer Experience
Exceptional
OpenAPI Support
One of a kind





























