An open API service indexing awesome lists of open source software.

https://github.com/ofabiodev/elysia-routing

🧭 Declarative routing for Elysia that turns simple definitions into clean predictable routes.
https://github.com/ofabiodev/elysia-routing

autoroute autorouting elysia elysia-plugin elysiajs middleware

Last synced: 5 months ago
JSON representation

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

Awesome Lists containing this project

README

          


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

```bash
# Using Bun
bun add elysia-routing
```

```bash
# Using NPM
npm install elysia-routing
```

```bash
# 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

```ts
import { defineRoute } from "elysia-routing"

export default defineRoute({
handler: () => ({ message: "Hello World" })
})
```

routes/users/[id]/index.get.ts

```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

```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](LICENSE) © [ofabiodev](https://github.com/ofabiodev)