A minimal routing library designed to sit on top of Bun's fast HTTP server. Based on Radix Tree.
Sio=Hot Pao=Bun
bun add siopao
import { Siopao } from 'siopao'
const app = new Siopao()
app.get('/ping', () => new Response('pong'))
// Named route
app.get('/path/:name', (request) => {
return Response.json({
name: request.params.name
})
})
// Wildcard route
app.use('/path/foo/**', (request) => {
return new Response('Wildcard route')
})
// Named Wildcard route
app.use('/path/foo/**:name', (request) => {
return new Response('Named Wildcard route')
})
app.serve({ port: 3000 }, () => {
console.log('Listening on port 3000...')
})
If you have custom logic to add inside Bun's fetch option, you can use the fetch
method instead:
const app = new Siopao()
app.get('/ping', () => new Response('pong'))
Bun.serve({
port: 3000,
fetch: (request) => {
// Custom logic here
return app.fetch(request)
}
})
For a more complete fully type-safe web framework, check out Elysia.
MIT