https://github.com/mariofdezzz/toruk
🦕 Deno router fast, lightweight, close to runtime best practices
https://github.com/mariofdezzz/toruk
deno router
Last synced: 4 months ago
JSON representation
🦕 Deno router fast, lightweight, close to runtime best practices
- Host: GitHub
- URL: https://github.com/mariofdezzz/toruk
- Owner: mariofdezzz
- License: mit
- Created: 2023-01-03T17:36:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-04T13:01:06.000Z (almost 2 years ago)
- Last Synced: 2024-09-06T14:30:14.670Z (almost 2 years ago)
- Topics: deno, router
- Language: TypeScript
- Homepage: https://toruk.mariofdezzz.dev
- Size: 83 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Toruk

Deno router fast, lightweight, close to runtime best practices.
The easiest way to enjoy Deno.
## Getting Started
```ts
import { App } from 'https://deno.land/x/toruk/mod.ts'
new App()
.get('/', () => new Response('Hello World'))
.get('/users/:id', ({ params }) => new Response(`User ${params.id}`))
.serve()
```
Path uses [URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern/URLPattern) matching.
Handler functions follow the same signature as [Deno's serve handler](https://deno.land/api@v1.44.4?s=Deno.ServeHandler).
```ts
import { App } from 'https://deno.land/x/toruk/mod.ts'
new App()
.post('/users/:id/posts', async ({ request, info, params }) => {
const body = await request.json()
return new Response(`Post ${body.id} created for user ${params.id}`)
})
.serve()
```
## Alternative Syntaxes
### Object
```ts
import { App } from 'https://deno.land/x/toruk/mod.ts'
new App({
router: {
routes: [
{
path: '/',
handler: () => new Response('Hello World'),
children: [
{
path: 'users/:id',
handler: ({ params }) => new Response(`User ${params.id}`),
},
],
},
],
},
})
.serve()
```
## Middlewares
```ts
import { App } from 'https://deno.land/x/toruk/mod.ts'
import { cors } from 'https://deno.land/x/toruk/middlewares/mod.ts'
new App()
.use(cors())
.get('/', () => new Response('Hello World'))
.serve()
```