Skip to content
Curved text logo saying 'Elysia JS'

人体工程学 框架

具有 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 行代码

更加先进的 类型安全

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 feels 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
)
}) ) })

向您的实际 API 打招呼,使用 OpenAPI

我们认真对待 OpenAPI 文档

与 OpenAPI 模式深度集成
Elysia 可以开箱即用地生成 API 文档。

OpenAPI features, all in 1 line

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

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

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
对于 DevOps

OpenTelemetry

Elysia 原生支持 OpenTelemetry。监控功能内置,因此您可以轻松监控您的服务,无论平台如何。

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
})
对于前端

端到端类型安全

像 tRPC 一样,Elysia 提供从后端到前端的类型安全,而无需代码生成。前端和后端之间的交互在编译时和运行时都经过类型检查。

21x

比 Express 更快

6x

比 Fastify 更快

  1. Elysia Bun
    2,454,631 reqs/s
  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 结果。

充满信心地 进行测试

类型安全带有 自动完成功能

Elysia 提供了一个类型安全层,用于与您的服务器进行交互和测试,涵盖从路由到参数的各个环节。

借助自动补全功能,您可以轻松为服务器编写测试,无需任何繁琐操作。

typescript
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
({
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
: '用户名已被占用'
}) })

人们怎么说

Elysia Logo Elysia

由你实现

Elysia 不属于任何组织 ,由志愿者和社区驱动。 Elysia 的实现得益于这些出色的赞助商。

Thank you for making Elysia possible

We can only develop Elysia full-time thanks to your supports.

With love from our community

Elysia Logo
Elysia Logo

Elysia

Ergonomic Framework for Humans

Speed

Top Performance

Type Safety

Best in class

Developer Experience

Exceptional

OpenAPI Support

One of a kind