elysia
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "elysia":https://skillpi.com/zh/skills/deepskill-95bf0f5d3e8f86a618051f71a115f8297eb9676d9474307d57edf30b36003747。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用 Elysia 在 Bun 上构建高性能 API。适用于用 Bun 创建 API、使用 Elysia 构建 REST API、在 Bun 上搭建 WebSocket 服务器、使用 Eden Treaty 实现类型安全的 API、Elysia 插件开发,以及最快的 TypeScript HTTP 框架相关场景。涵盖 REST 路由、WebSocket 支持、基于 TypeBox 的数据验证、使用 Eden Treaty 实现类型安全的客户端、插件开发、身份验证守卫(Auth Guards)和 OpenAPI/Swagger 文档自动生成。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 适合谁
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: elysia
description: >-
Build high-performance APIs with Elysia on Bun. Use when someone asks to
"create an API with Bun", "build a REST API with Elysia", "set up WebSocket
server on Bun", "type-safe API with Eden Treaty", "Elysia plugin", or
"fastest TypeScript HTTP framework". Covers REST routes, WebSocket, validation
with TypeBox, Eden Treaty type-safe client, plugins, auth guards, and
OpenAPI/Swagger generation.
license: Apache-2.0
compatibility: "Bun 1.0+. TypeScript."
metadata:
author: terminal-skills
version: "1.0.0"
category: development
tags: ["bun", "api", "typescript", "websocket", "elysia"]Elysia
Overview
Elysia is a Bun-native HTTP framework built for speed and developer experience. End-to-end type safety from server to client via Eden Treaty, schema validation baked in, and performance that rivals Go/Rust frameworks. Think Express but with types, on Bun.
When to Use
- Building REST APIs on Bun (instead of Express/Fastify)
- Need end-to-end type safety — server defines routes, client auto-infers types
- WebSocket server with typed messages
- High-performance API that needs to handle 100K+ req/sec
- Rapid prototyping with auto-generated OpenAPI/Swagger docs
Instructions
Getting Started
bun create elysia my-api
cd my-api
bun run dev
Basic REST API
// src/index.ts — Elysia REST API with validation
/**
* Type-safe REST API using Elysia.
* Body/query/params are validated at runtime AND typed at compile time.
* No separate type definitions needed — schema IS the type.
*/
import { Elysia, t } from "elysia";
const app = new Elysia()
// GET with typed query params
.get("/users", async ({ query }) => {
const { page, limit } = query;
// page and limit are typed as numbers
return { users: [], page, limit };
}, {
query: t.Object({
page: t.Number({ default: 1 }),
limit: t.Number({ default: 20, maximum: 100 }),
}),
})
// POST with body validation
.post("/users", async ({ body }) => {
// body is typed as { name: string, email: string }
const user = { id: crypto.randomUUID(), ...body, createdAt: new Date() };
return user;
}, {
body: t.Object({
name: t.String({ minLength: 2, maxLength: 100 }),
email: t.String({ format: "email" }),
}),
})
// Path params + response schema
.get("/users/:id", async ({ params, error }) => {
const user = await findUser(params.id);
if (!user) return error(404, { message: "User not found" });
return user;
}, {
params: t.Object({
id: t.String({ format: "uuid" }),
}),
})
// DELETE with auth guard
.delete("/users/:id", async ({ params }) => {
await deleteUser(params.id);
return { deleted: true };
}, {
params: t.Object({ id: t.String() }),
beforeHandle: ({ headers, error }) => {
if (headers.authorization !== `Bearer ${process.env.ADMIN_TOKEN}`) {
return error(401, { message: "Unauthorized" });
}
},
})
.listen(3000);
console.log(`🦊 Elysia running at ${app.server?.url}`);
WebSocket
// src/ws.ts — Type-safe WebSocket with Elysia
import { Elysia, t } from "elysia";
const app = new Elysia()
.ws("/chat", {
body: t.Object({
type: t.Union([t.Literal("message"), t.Literal("ping")]),
content: t.Optional(t.String()),
room: t.String(),
}),
open(ws) {
const room = ws.data.query.room || "general";
ws.subscribe(room);
ws.publish(room, JSON.stringify({ type: "system", content: `User joined ${room}` }));
},
message(ws, { type, content, room }) {
if (type === "message" && content) {
ws.publish(room, JSON.stringify({ type: "message", content, from: ws.id }));
}
if (type === "ping") {
ws.send(JSON.stringify({ type: "pong" }));
}
},
close(ws) {
ws.unsubscribeAll();
},
})
.listen(3000);
Eden Treaty — Type-Safe Client
// client.ts — Auto-typed API client generated from Elysia server
/**
* Eden Treaty creates a fully typed client from your Elysia app type.
* No codegen, no OpenAPI parsing — just TypeScript inference.
*/
import { treaty } from "@elysiajs/eden";
import type { App } from "./src/index"; // Import the app TYPE
const api = treaty<App>("localhost:3000");
// All methods, params, body, and responses are fully typed
const { data: users } = await api.users.get({ query: { page: 1, limit: 10 } });
// ^? { users: User[], page: number, limit: number }
const { data: newUser } = await api.users.post({
name: "Kai",
email: "kai@example.com",
});
// ^? { id: string, name: string, email: string, createdAt: Date }
const { error } = await api.users({ id: "bad-id" }).delete();
// ^? { message: string } | null
Plugins and Middleware
// src/app.ts — Elysia with plugins
import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
import { jwt } from "@elysiajs/jwt";
const app = new Elysia()
.use(cors())
.use(swagger({
documentation: {
info: { title: "My API", version: "1.0.0" },
},
}))
.use(jwt({
name: "jwt",
secret: process.env.JWT_SECRET!,
exp: "7d",
}))
// Auth guard as derive
.derive(async ({ jwt, headers, error }) => {
const token = headers.authorization?.replace("Bearer ", "");
if (!token) return { user: null };
const payload = await jwt.verify(token);
if (!payload) return { user: null };
return { user: payload as { id: string; email: string } };
})
// Protected route
.get("/me", ({ user, error }) => {
if (!user) return error(401, { message: "Not authenticated" });
return user;
})
.listen(3000);
export type App = typeof app;
Group Routes
// src/routes/users.ts — Route group with shared prefix and guards
import { Elysia, t } from "elysia";
export const usersRoutes = new Elysia({ prefix: "/users" })
.get("/", () => listUsers())
.get("/:id", ({ params }) => getUser(params.id), {
params: t.Object({ id: t.String() }),
})
.post("/", ({ body }) => createUser(body), {
body: t.Object({
name: t.String(),
email: t.String({ format: "email" }),
}),
});
// Main app
import { Elysia } from "elysia";
import { usersRoutes } from "./routes/users";
const app = new Elysia()
.use(usersRoutes)
.listen(3000);
Examples
Example 1: Build a CRUD API with auth
User prompt: "Create a REST API for a todo app with JWT auth, input validation, and Swagger docs using Elysia on Bun."
The agent will create an Elysia app with JWT plugin, CRUD routes for todos with TypeBox validation, auth guards on mutation routes, and auto-generated Swagger at /swagger.
Example 2: Real-time chat server
User prompt: "Build a WebSocket chat server with rooms using Elysia."
The agent will set up Elysia WebSocket with typed messages, room subscription via pub/sub, and a REST endpoint to list active rooms.
Guidelines
- Use
t.Object()for all inputs — runtime validation + compile-time types in one declaration - Export the app type —
export type App = typeof appenables Eden Treaty client - Group routes with
new Elysia({ prefix })— keeps route files modular derivefor auth — compute user from JWT once, available in all routesbeforeHandlefor guards — return an error to short-circuit the request- Bun is required — Elysia uses Bun-specific APIs; it won't work on Node.js
- Performance: Elysia handles 100K+ req/s — benchmark before adding middleware that might slow it down
- Swagger plugin at
/swagger— auto-generated from your route schemas, zero config
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- Elysia+Bun组合为开发者提供高性能API构建方案,满足现代Web开发高频需求
- 涵盖REST、WebSocket、类型安全客户端、插件开发等完整生态,实用价值高
亮点
- 触发词覆盖全面,包含多种常见开发场景表述
- 边界清晰,能有效区分Elysia与其他框架的使用场景
亮点
- 文档结构完整,包含Overview、When to Use、Instructions、Examples等必要章节
- 代码示例丰富且规范,涵盖基础用法到高级特性
- frontmatter信息完整,包含兼容性、作者、版本等关键信息
亮点
- 所有代码示例均包含完整的错误处理和类型验证
- 工具链依赖明确(Bun 1.0+),参数使用规范
- 提供了身份验证、数据验证等关键安全机制的实现
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。