Attributes
Includes Deno configuration
Repository
Current version released
2 months ago
Toruk
Deno router fast, lightweight, close to runtime best practices. The easiest way to enjoy Deno.
Getting Started
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 matching.
Handler functions follow the same signature as Deno’s serve handler.
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
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
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()