Native Package Manager

    siopao
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.6 • Public • Published

    siopao

    npm (tag) NPM

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

    Sio=Hot Pao=Bun

    Installation

    bun add siopao

    Usage

    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')
    })
    
    // Same as Bun.serve options but without the fetch option
    app.serve({ port: 3000 })
    
    // Callback style
    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 web framework for the Bun runtime, see Bao.js.

    License

    MIT

    Keywords

    Install

    npm i siopao

    DownloadsWeekly Downloads

    17

    Version

    0.2.6

    License

    MIT

    Unpacked Size

    10.5 kB

    Total Files

    10

    Last publish

    Collaborators

    • wobsoriano