Ecosyste.ms: Awesome

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

https://github.com/wobsoriano/siopao

A minimal routing library designed to sit on top of Bun's fast HTTP server.
https://github.com/wobsoriano/siopao

bun http router

Last synced: about 1 month ago
JSON representation

A minimal routing library designed to sit on top of Bun's fast HTTP server.

Lists

README

        

# siopao

[![npm (tag)](https://img.shields.io/npm/v/siopao?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/siopao) ![NPM](https://img.shields.io/npm/l/siopao?style=flat&colorA=000000&colorB=000000)

A minimal routing library designed to sit on top of [Bun](https://github.com/Jarred-Sumner/bun)'s [fast HTTP server](https://bun.sh/docs/api/http). Based on [Radix Tree](https://github.com/unjs/radix3).

Sio=Hot Pao=Bun

## Installation

```bash
bun add siopao
```

## Usage

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

```ts
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](https://elysiajs.com/).

## License

MIT