File-based routing for Elysia with built-in type-safe validation.
Stop manually registering routes. elysia-routing scans your file structure and automatically creates routes based on filenames. Add type-safe validation with zero dependencies, keep your codebase organized, and scale without the boilerplate.
# Using Bun
bun add elysia-routing |
# Using NPM
npm install elysia-routing |
# Using Yarn
yarn add elysia-routing |
| Convention | Example | Result |
|---|---|---|
(group) |
(admin)/dashboard.get.ts |
GET /dashboard |
[param] |
users/[id]/index.get.ts |
GET /users/:id |
index |
users/index.post.ts |
POST /users |
name.method |
users/profile.get.ts |
GET /users/profile |
.all |
health.all.ts |
All HTTP methods |
routes/index.get.ts |
import { defineRoute } from "elysia-routing"
export default defineRoute({
handler: () => ({ message: "Hello World" })
}) |
routes/users/[id]/index.get.ts |
import { defineRoute, v } from "elysia-routing"
export default defineRoute({
schema: {
params: v.object({
id: v.string()
})
},
handler: ({ params }) => ({
user: { id: params.id }
})
}) |
routes/users/index.post.ts |
import { defineRoute, v } from "elysia-routing"
export default defineRoute({
schema: {
body: v.object({
name: v.string().min(3),
email: v.string().regex(/^[^\s@]+@[^\s@]+\.[^\s@]+$/),
age: v.number().min(18)
})
},
handler: ({ body }) => ({
created: body
})
}) |