⚡️A minimalistic and sweet router for blazing fast bun

Overview

banner release GitHub License PRs Welcome PRs Welcome

Melonpan is a simple and minimalistic web-router designed to work with Bun, keeping performance in mind.

🤔 Why Melonpan?

  • no/minimal learning curve
  • Developer focused, you just need to focus on buisness logic
  • 0 bloat functions
  • 0 dependencies
  • 100% Typescript code
  • Blazing fast performance than node webframework alternatives

⚡️ Quickstart

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);
    }
}

🤖 Benchmarks

The following results are of:

  • Test: Bun (v0.1.11) + Melonpan (v0.1.0) Vs NodeJS (v16.13.0) + Express (v4.18.1)
  • Machine: MacBook M1 Pro 16GB RAM
  • Benchmarking tool used: Autocannon

Results

benchmark

Almost an 8x performance, thanks to Bun.

You can find the benchmark suite here

⬇️ Installation

Using Bun

  1. Install Bun
curl https://bun.sh/install | bash
  1. Add Melonpan as dependency using bun
bun add melonpan

Using Yarn

yarn add melonpan

Using NPM

npm install melonpan

🤝 Contributions

  • Feel Free to Open a PR/Issue for any feature or bug(s).
  • Make sure you follow the community guidelines.
  • Feel free to open an issue to ask a question/discuss anything about melonpan.
  • Have a feature request? Open an Issue!
  • Please ensure to run bun test before submitting your PRs!

📢 Shoutouts

Shoutout to Khyati Gupta for amazing logo and banner illustrations

License

Copyright 2022 Hemanth Krishna

Licensed under MIT License : https://opensource.org/licenses/MIT

Made with , multiple cups of coffee and some chaii

Comments
  • Exporting more from root

    Exporting more from root

    Using typescript I had to go around looking for exports like MelonContext etc. the root package should export these. At some level I also feel like the Melon prefix from these classes should be removed because they are adding stutter to names. But for now I am sticking to the original convention.

    opened by maxpert 1
  • Add res as response option

    Add res as response option

    Without this pull request, there were be only two response options: json and text. It is necessary to have a res response option to send a simple new Response() object.

    opened by Triste-le-Roy 0
  • Fix exported types errors

    Fix exported types errors

    There is an error in the exporting statements. Typescript 3.8 introduces new syntax for type-only exports, which are not being used. This pull request will fix the problem.

    opened by Triste-le-Roy 0
  • Indirectly exported binding name 'MelonHandler' is not found.

    Indirectly exported binding name 'MelonHandler' is not found.

    Hello.

    I cloned the latest version of this repository and when I ran bun index.ts there was an error, which is: indirectly exported binding name 'MelonHandler' is not found. The error happens in the latest version because in 0.1.1 and 0.1.0 it works fine.

    Thank you.

    opened by Triste-le-Roy 0
  • Enhancement: Take in default `httpStatusCode` as 200 in `ctx.text()` and `ctx.json()`

    Enhancement: Take in default `httpStatusCode` as 200 in `ctx.text()` and `ctx.json()`

    Currently in the functions ctx.text(statusCode, data) and ctx.json(statusCode, data) has statusCode at the start.

    Request

    Convert the above functions to:

    • ctx.text(statusCode, data) --> ctx.text(data, statusCode, options)
    • ctx.json(statusCode, data) --> ctx.json(data, statusCode, options)

    And ensure the default response code is 200 if not passed

    Action Items

    • [ ] Fix Codebase to do so
    • [ ] Update readme and relevant docs to reflect the same
    documentation enhancement good first issue 
    opened by DarthBenro008 0
  • feat: melon context

    feat: melon context

    This PR contains the following:

    • Implementation of MelonContext that allows for:
      • ctx.json()
      • ctx.text()
    • Default handler using the app.get("*", (req, ctx) => ctx.text(200, "default handler"))
    • Fix for / route being trimmed due to trailing sanitisation
    opened by DarthBenro008 0
  • feat: clean router and middleware support

    feat: clean router and middleware support

    This PR adds the following support:

    • Ability to register multiple routers to multiple paths [15f4cc32529402b8210c84490c28fb5f01beaa40]
    • Ability to register global and router-specific middlewares [0109d634d7d2354e805713aca250b168ecb59007, dac8114f6b326fe5416e6f15642e257d6cd908a2]
    • Introduces a RouterInternalUtility class in 6cdf61118b4b17d002b17abb7f91bdcddc59a112

    Notes

    Untitled (Draft)-1

    opened by DarthBenro008 0
  • Add CORS with default headers

    Add CORS with default headers

    Captura de pantalla de 2022-10-17 20-50-11 Fix: to add a new property private headers: Headers; in Melonpan, which contains all set headers, in order to pass them as a param in all the new Response() objects. So now we just need to call melonpan.cors() to set all the default headers, which are:

    [
      ["Access-Control-Allow-Origin", "*"]
      ["Access-Control-Allow-Methods", "POST, GET, OPTIONS"]
      ["Access-Control-Allow-Headers", "X-PINGOTHER, Content-Type"]
      ["Access-Control-Max-Age", "86400"]
    ]
    
    opened by Triste-le-Roy 0
  • CORS policy

    CORS policy

    Captura de pantalla de 2022-10-17 20-50-11 This error occurs because the Access-Control-Allow-Origin: * header is not present in the new Response() object. In the dev environment we need the headers so the client has not problems in reaching the requested resources. Fix: to add a new property private headers: Headers; in Melonpan, which contains all set headers, in order to pass them as a param in all the new Response() objects. So now we just need to call melonpan.cors() to set all the default headers, which are:

    [
      ["Access-Control-Allow-Origin", "*"]
      ["Access-Control-Allow-Methods", "POST, GET, OPTIONS"]
      ["Access-Control-Allow-Headers", "X-PINGOTHER, Content-Type"]
      ["Access-Control-Max-Age", "86400"]
    ]
    

    I shall make a pull request to fix it.

    opened by Triste-le-Roy 0
Releases(0.1.1)
Owner
Hemanth Krishna
Google SoC'21 @litmuschaos | LFX Mentee Q1'21 @cncf @keptn | k8s | Fullstack | Gopher | Rustcean | Distributed Systems
Hemanth Krishna
Fast, Bun-powered, and Bun-only(for now) Web API framework with full Typescript support.

Zarf Fast, Bun-powered, and Bun-only(for now) Web API framework with full Typescript support. Quickstart Starting with Zarf is as simple as instantiat

Zarf Framework 65 Dec 28, 2022
A blazingly fast Bun.js filesystem router, with an unpleasantly smooth experience!

Oily A blazingly fast Bun.js filesystem router, with an unpleasantly smooth experience! Installation · Usage · Examples · Discord Installation Once yo

Aries 22 Dec 19, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Keep your Twitter feed sweet!

Bitter Blocker Keep your Twitter feed sweet! Introducing Bitter Blocker, the Chrome extension that blocks negative tweets! No more scrolling through y

Bart 3 Apr 26, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A sweet MERN Stack app to add food recipes to your own Cook Book!

Welcome to LeCookBook ?? A sweet MERN Stack project, that lets you view, quicksearch, search by category and a randomizer with a cool UI. This page ha

Rene Ortega 2 Jun 3, 2022
Fast, and friendly Bun web framework

?? KingWorld Fast, and friendly Bun web framework. ⚡️ Faster than Express.js by 8.5x on M1 Max Named after my favorite VTuber (Shirakami Fubuki) and c

SaltyAom 114 Jan 4, 2023
Fast Differentiable Tensor Library in JavaScript and TypeScript with Bun + Flashlight

A fast differentiable tensor library for research in TypeScript and JavaScript. Built with bun + flashlight. ⚠️ This is experimental software! ⚠️ Usag

Meta Research 917 Jan 7, 2023
Gatsby-blog-cosmicjs - 🚀⚡️ Blazing fast blog built with Gatsby and the Cosmic Headless CMS 🔥

Gatsby + Cosmic This repo contains an example blog website that is built with Gatsby, and Cosmic. See live demo hosted on Netlify Uses the Cosmic Gats

Priya Chakraborty 0 Jan 29, 2022
⚡ A blazing fast, lightweight, and open source comment system for your static website, blogs powered by Supabase

SupaComments ⚡ A blazing fast, lightweight, and open source comment system for your static website, blogs ?? Demo You can visit the Below demo blog po

MC Naveen 112 Dec 27, 2022
An open-source, blazing fast code editor for Windows, Mac, and Linux.

Thermite An open-source, blazing fast code editor for Windows, Mac, and Linux. About Thermite is a Blazing Fast, Open-Source, Cross-Platform Code Edit

Keston 4 Oct 25, 2022
🔥 Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio.

mydramalist API ?? Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio. Setup pnpm install node index.js available at http:/

Paranjay Singh 6 Dec 4, 2022
Blazing fast and lightweight state management framework 👓

StateX is a blazing fast and lightweight framework for managing state in a Javascript app. Features ?? Fast − Our APIs just run lightning fast, no mor

Truelines 7 Oct 8, 2022
🦆 lightning fast duckdb bindings for bun runtime

@evan/duckdb lightning fast duckdb bindings for bun runtime Install bun add @evan/duckdb Features ?? batteries included ?? jit optimized bindings ?? 4

evan 29 Oct 20, 2022
A minimal routing library designed to sit on top of Bun's fast HTTP server.

siopao 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 Us

Robert Soriano 69 Nov 8, 2022
⚡️ A fast, minimalist web framework for the Bun JavaScript runtime

?? Bao.js A fast, minimalist web framework for the Bun JavaScript runtime. ⚡️ Bao.js is 3.7x faster than Express.js and has similar syntax for an easy

Matt Reid 746 Dec 26, 2022
🚀 Blazing Fast S3 Powered CDN ✨ Powered By Fastify, S3 Buckets & Docker!

?? WasiCDN Blazing Fast S3 Powered CDN, Powered By Fastify, S3 Compatible Buckets & Docker! Core DockerHub: https://hub.docker.com/r/maximking19/wasic

Maxim 5 Aug 31, 2022
Blazing fast 🔥 Discord Desktop Client.

Fastcord Faster Discord Desktop Client Made with Rust & React Motivation Discord is cool but electron is not. Discord Desktop consumes too much memory

fishuke 12 Nov 21, 2022