0.8.1 • Published 2 years ago

bun-router v0.8.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years 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

2 years ago

0.8.0

2 years ago

0.7.3

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.8

2 years ago

0.5.5

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.9

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago