核心特性
简洁的 API、强大的类型推断、内置验证,专为高效开发设计
极致性能
比 Express 快 1.8x
JIT 编译验证器 · Radix Tree 路由
类型安全
端到端类型推断
Schema → Type · 跨文件类型
声明式路由
结构即真相
路由即数组 · 显式中间件
跨运行时
一套代码,任意环境
Node.js · Bun · Cloudflare Workers
比 Express 更快
请求/秒
- ElysiaBun~118K
- VafastBun~101K
- HonoBun~56K
- ExpressNode~56K
测试环境:Bun 1.2.20, macOS, wrk (4线程, 100连接, 30s)
为开发者而生
API 设计符合直觉,几乎没有学习成本。不搞复杂抽象,你写的代码就是最终运行的样子。
import { Server, defineRoute, defineRoutes } from 'vafast'
const routes = defineRoutes([
defineRoute({
method: 'GET',
path: '/',
handler: () => 'Hello World'
}),
defineRoute({
method: 'GET',
path: '/json',
handler: () => ({ message: 'Hello World' })
})
])
const server = new Server(routes)
export default { fetch: server.fetch }自动响应
返回对象自动转 JSON,返回字符串自动设置 Content-Type
语义化错误
内置 err.notFound() 等方法,统一错误响应格式
声明式路由
路由就是数组,所有接口一目了然
跨运行时
同一份代码跑在 Node.js、Bun、Workers
从请求到响应,全程有类型
类型自动同步
服务端定义好接口,客户端自动获得完整类型提示,不用手动写类型、不用生成代码。
import { Server, defineRoute, defineRoutes, Type, err } from 'vafast'
const routes = defineRoutes([
defineRoute({
method: 'PATCH',
path: '/profile',
schema: { body: Type.Object({ age: Type.Number() }) },
handler: ({ body }) => {
if (body.age < 18)
throw err.badRequest('年龄不足')
return { success: true, data: body }
}
})
])
const server = new Server(routes)
// 导出类型供客户端使用
export type AppRoutes = typeof routesimport { eden, createClient, type InferEden } from '@vafast/api-client'
import { defineRoute, defineRoutes, Type } from 'vafast'
// 定义并处理路由
const routes = defineRoutes([
defineRoute({
method: 'PATCH',
path: '/profile',
schema: { body: Type.Object({ age: Type.Number() }) },
handler: ({ body }) => ({ success: true, data: body })
})
])
// ✅ 类型推断自动工作,无需 as const!
type Api = InferEden<typeof routes>
const api = eden<Api>(createClient('https://api.example.com'))
// 完整类型提示 + 自动补全
const { data } = await api.profile.patch({
age: 21
})错误提前暴露
缺少字段、类型不对?写代码时 IDE 就会提示,不用等到运行才发现问题。配合 @vafast/api-client,测试代码也能享受完整的类型推断。
import { eden, createClient, type InferEden } from '@vafast/api-client'
import { defineRoute, defineRoutes, Type } from 'vafast'
// 定义并处理路由
const routes = defineRoutes([
defineRoute({
method: 'PUT',
path: '/user',
schema: { body: Type.Object({ username: Type.String(), password: Type.String() }) },
handler: ({ body }) => ({ success: true, message: '用户创建成功' })
})
])
// ✅ 类型推断自动工作
type Api = InferEden<typeof routes>
const api = eden<Api>(createClient('http://localhost:3000'))
// ❌ 缺少 password 字段 → 编译时报错
const { data } = await api.user.put({ username: 'mika'
})一套代码,到处运行
基于 Web 标准 Fetch API 构建,不绑定任何运行时。同一份代码可以部署到 Node.js、Bun、Cloudflare Workers 等任意平台。
由你实现
Vafast 不是由某个组织拥有,而是由社区推动。您的支持让 Vafast 得以持续发展。
Thank you for making Vafast possible