elysia
БесплатноБез исполняемых скриптовНе проверенBuild typed HTTP and WebSocket APIs with Elysia, a TypeScript web framework optimized for Bun that also runs on Node.js. Use when someone asks to "create an…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Elysia
Overview
Elysia is a TypeScript HTTP framework optimized for Bun (current release 1.4). It gives end-to-end type safety from server to client via Eden Treaty, built-in schema validation, and an OpenAPI plugin that documents routes from the same schemas. It also runs on Node.js through an adapter. Think Express, but with types.
Package scopes: the official docs now install plugins from @elysia/* (@elysia/cors, @elysia/jwt, @elysia/openapi, @elysia/eden, @elysia/node). The older @elysiajs/* names are still published and carry the same releases, so existing projects keep working. @elysiajs/swagger is deprecated; use the OpenAPI plugin.
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
- Fast APIs where framework overhead matters
- Rapid prototyping with auto-generated OpenAPI docs (Scalar UI)
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, status }) => {
const user = await findUser(params.id);
if (!user) return status(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, status }) => {
if (headers.authorization !== `Bearer ${process.env.ADMIN_TOKEN}`) {
return status(401, { message: "Unauthorized" });
}
},
})
.listen(3000);
console.log(`Elysia running at ${app.server?.hostname}:${app.server?.port}`);
WebSocket
// src/ws.ts — Type-safe WebSocket with Elysia
import { Elysia, t } from "elysia";
const app = new Elysia()
.ws("/chat", {
query: t.Object({ room: t.Optional(t.String()) }),
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) {
// leave every topic this socket joined
for (const topic of ws.subscriptions) ws.unsubscribe(topic);
},
})
.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 "@elysia/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: "[email protected]",
});
// ^? { id: string, name: string, email: string, createdAt: Date }
const { error } = await api.users({ id: "bad-id" }).delete();
// error is null on success; otherwise { status: 401 | 422, value: ... }
if (error) console.error(error.status, error.value);
Plugins and Middleware
// src/app.ts — Elysia with plugins
import { Elysia } from "elysia";
import { cors } from "@elysia/cors";
import { openapi }
Установить elysia в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл elysia?
Build typed HTTP and WebSocket APIs with Elysia, a TypeScript web framework optimized for Bun that also runs on Node.js. 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 documentation.
Как установить скилл elysia?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл elysia запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic