Skip to content
弯曲文本徽标显示 'Elysia JS'

人体工程学框架 for 人类

具有 端到端类型安全的 TypeScript、类型完整性以及卓越的开发者体验。 由 Bun 超级增强。

开始使用
bun create elysia app

看看为什么开发者喜爱 Elysia

第一个生产就绪的、
并且最受欢迎的 Bun 框架

Trusted by team at

X/TwitterX/TwitterX/TwitterBank for Agriculture and Agricultural Cooperatives ThailandX/TwitterX/TwitterDecidable logo

我们的原则

为人类设计

我们的目标是设计一个符合人体工程学、合理且高效的框架,即使是初学者也能轻松使用

设计时避免不必要的复杂性和类型复杂性,让您专注于构建

一个感觉 就像 JavaScript 的框架

typescript
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)

只需返回

一个字符串、数字或复杂的 JSON

我们只需返回

内置文件支持

要发送文件或图像,只需返回

不多不少

流式响应

使用 yield 来流式响应

我们只需返回

实时数据

内置 µWebSocket

只需 3 行代码发送实时数据

21x

比 Express 更快

6x

比 Fastify 更快

  1. Elysia Bun
    2,454,631 请求/秒
  2. Gin Go

    676,019

  3. Spring Java

    506,087

  4. Fastify Node

    415,600

  5. Express Node

    113,117

  6. Nest Node

    105,064

以每秒请求次数进行测量。数据来源于官方 TechEmpower 基准测试 第 22 轮(2023-10-17)的 PlainText 结果。

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

顶级水平 类型安全

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.

ts
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
())
}) })
ts
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
())
}) })
ts
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
())
}) })
ts
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[]'
}) })
ts
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
)
}) ) })

Say hello to your actual API with OpenAPI

We take OpenAPI documentation seriously

With deep integration with OpenAPI schema
Elysia can generate API documentation out of the box

OpenAPI features, all in 1 line

Just 1 line of code, you get a full-fledged API documentation effortlessly

And with OpenAPI Type Gen, Elysia can turn TypeScript types into an API documentation (like FastAPI but from TypeScript types)

typescript
import { Elysia } from 'elysia'
import { openapi } from '@elysiajs/openapi'

new Elysia()
	.use(openapi())
	.listen(3000)
typescript
import { Elysia } from 'elysia'
import { openapi, fromTypes } from '@elysiajs/openapi'

export const app = new Elysia()
	.use(
		openapi({
			references: fromTypes()
		})
	)

11.88ms

POST /character/:id/chat

Playback

Request
Validation
Transaction
Upload
Sync
For DevOps

OpenTelemetry

Elysia has 1st party support for OpenTelemetry. Instrumentation is built-in, so you can easily monitor your services regardless of the platform.

typescript
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
})
For Frontend

End-to-end Type Safety

Like tRPC, Elysia provides type-safety from the backend to the frontend without code generation. The interaction between frontend and backend is both type-checked at compile and runtime.

自信地 测试

通过 自动补全 实现类型安全

Elysia 提供了一个类型安全的层,用于与服务器交互和测试,从路由到参数。

借助自动补全,您可以轻松编写服务器测试,而无需任何麻烦。

typescript
import { 
treaty
} from '@elysiajs/eden'
import {
app
} from './index'
import {
test
,
expect
} from 'bun:test'
const
server
=
treaty
(
app
)
test
('should handle duplicated user', async () => {
const {
error
} = await
server
.
user
.
put
({
Argument of type '{ username: string; }' is not assignable to parameter of type '{ username: string; password: string; }'. Property 'password' is missing in type '{ username: string; }' but required in type '{ username: string; password: string; }'.
username
: 'mika',
})
expect
(
error
?.
value
).
toEqual
({
success
: false,
message
: 'Username already taken'
}) })

What people say about

Elysia Logo Elysia

Because of You

Elysia is not owned by an organization, driven by volunteers, and community. Elysia is possible by these awesome sponsors.

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 徽标
Elysia 徽标

Elysia

专为人类设计的框架

速度

顶级性能

类型安全

同类最佳

开发者体验

出色

OpenAPI 支持

独一无二

用 💖 为 构建