0.8.1 • Published 7 months ago

bun-router v0.8.1

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

Bun router

Usage

npm i -s bun-router

or

bun i bun-router

Examples

URL Parameters
import { Router, http } from 'bun-router';

const router = Router();

router.add('/', 'GET', () => http.ok());

router.get('/u/:username', ctx => {
    const username = ctx.params.get('username');

    if (!username) return http.badRequest();

    return ctx.json({ username: username });
});

router.serve();
Static

Read a directory and serve it's contents. .tsx and .html files are rendered by default, everything else is served, including the extension.

Ex: /assets/gopher.png would serve a .png image. /home would be .tsx or .html depending on extension.

import { Router } from 'bun-router';

const router = Router();

router.static('/assets', 'static');

router.serve();
SQLite
import { Router } from 'bun-router'

const router = Router(3000, { db: 'test.db'});

router.post('/register', ctx => {
    const query = ctx.db.query("select 'Hello' as message;");

    return http.ok(query.get());
});
JSX
// ./pages/home.tsx
export default const Home = (title: string) => {
    return (
        <main>
            <h1>{ title }</h1>
        </main>
    );
};
// ./index.ts
import { Router } from 'bun-router';
import Home from './pages/home';

const router = Router();

router.get('/', ctx => ctx.render(Home('Hello World')))

router.serve();
0.8.1

7 months ago

0.8.0

7 months ago

0.7.3

8 months ago

0.7.2

8 months ago

0.7.1

8 months ago

0.7.0

9 months ago

0.6.0

9 months ago

0.5.8

9 months ago

0.5.5

9 months ago

0.5.4

9 months ago

0.5.3

9 months ago

0.5.0

9 months ago

0.4.0

9 months ago

0.3.9

9 months ago

0.3.8

9 months ago

0.3.7

9 months ago

0.3.6

9 months ago

0.3.5

9 months ago

0.3.4

9 months ago

0.3.1

9 months ago

0.3.0

9 months ago

0.2.8

10 months ago

0.2.7

10 months ago

0.2.6

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago