⚡️A minimalistic and sweet router for blazing fast bun
MIT License
import { Melonpan, MelonRouter } from "melonpan";
const melonpan = new Melonpan();
// Simple middleware definitions
melonpan.middleware((_req, ctx, next) => {
console.log("A middleware has been hit!")
})
// Easy query params parsing!
melonpan.get("/api/:id", (_req, ctx) => {
return ctx.json({"id": ctx.params.id}, 200);
})
// Routing done in very simple manner
melonpan.get("/" , (_req, ctx) => ctx.text("Hello world!"));
// Easy definitions of routers and handlers!
const melonRouter = new MelonRouter();
melonRouter.get("/bar", (_req, ctx) => ctx.text("this is a router", 200));
melonpan.use("/foo", melonRouter);
export default {
port: 3000,
fetch(req: Request){
return melonpan.serve(req);
}
}
The following results are of:
(v0.1.11)
+ Melonpan (v0.1.0)
Vs NodeJS (v16.13.0)
+ Express (v4.18.1)
Almost an 8x performance, thanks to Bun.
You can find the benchmark suite here
curl https://bun.sh/install | bash
bun add melonpan
yarn add melonpan
npm install melonpan
bun test
before submitting your PRs!Shoutout to Khyati Gupta for amazing logo and banner illustrations
Copyright 2022 Hemanth Krishna
Licensed under MIT License : https://opensource.org/licenses/MIT