Skip to content

🧭 Declarative routing for Elysia that turns simple definitions into clean predictable routes.

License

Notifications You must be signed in to change notification settings

ofabiodev/elysia-routing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elysia Routing Logo

Elysia Routing

File-based routing for Elysia with built-in type-safe validation.


GitHub Actions Workflow Status License NPM Downloads

Why Elysia Routing?

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.

Installation

# Using Bun
bun add elysia-routing
# Using NPM
npm install elysia-routing
# Using Yarn
yarn add elysia-routing

Supported Conventions

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

Examples

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
  })
})

License

MIT © ofabiodev

About

🧭 Declarative routing for Elysia that turns simple definitions into clean predictable routes.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published