Skip to content
Vafast

轻量、快速、类型安全

基于 TypeScript 的现代 Web 框架,声明式路由、自动类型推断、内置 Schema 验证

支持 Node.js、Bun、Cloudflare Workers

快速开始
$npx create-vafast-app
向下滚动了解更多

核心特性

简洁的 API、强大的类型推断、内置验证,专为高效开发设计

极致性能

比 Express 快 1.8x

JIT 编译验证器 · Radix Tree 路由

类型安全

端到端类型推断

Schema → Type · 跨文件类型

声明式路由

结构即真相

路由即数组 · 显式中间件

跨运行时

一套代码,任意环境

Node.js · Bun · Cloudflare Workers

1.8x

比 Express 更快

101K

请求/秒

  1. ElysiaBun
    ~118K
  2. VafastBun
    ~101K
  3. HonoBun
    ~56K
  4. ExpressNode
    ~56K

测试环境:Bun 1.2.20, macOS, wrk (4线程, 100连接, 30s)

为开发者而生

API 设计符合直觉,几乎没有学习成本。不搞复杂抽象,你写的代码就是最终运行的样子。

typescript
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

从请求到响应,全程有类型

类型自动同步

服务端定义好接口,客户端自动获得完整类型提示,不用手动写类型、不用生成代码。

server.ts
typescript
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
routes
client.ts
typescript
import { 
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,测试代码也能享受完整的类型推断。

typescript
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
({
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'
})

一套代码,到处运行

基于 Web 标准 Fetch API 构建,不绑定任何运行时。同一份代码可以部署到 Node.js、Bun、Cloudflare Workers 等任意平台。

Node.jsBunDenoWorkersVercelNetlify

由你实现

Vafast 不是由某个组织拥有,而是由社区推动。您的支持让 Vafast 得以持续发展。

Thank you for making Vafast possible

准备好了吗?

几分钟搭建你的第一个 Vafast 项目,体验高效的 API 开发

Vafast - 高性能 TypeScript Web 框架