Skip to content

Blazing fast backend, express-like library for Bun. 0 dependencies.

License

Notifications You must be signed in to change notification settings

Walikuperek/Bun-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http library for Bun

library card from blog

Read blog post about this library with cool explanation about internals ;)

Very fast HTTP server library based on Bun. Feel free to use it in your projects. Just copy the lib/src/http.

[!] To disable development mode inside your .env file set the PRODUCTION=true environment variable.

Usage

import { http, Res } from "./lib/src/http";

const str = (val: any) => JSON.stringify(val);

http.get("/", (req) => {
  return new Res(`Hello from home`);
});
http.get("/product/:productId", (req) => {
  return new Res(`Product (id: ${req.params.productId})`);
});
http.post("/blog/create", (req) => {
  return new Res(`
    params: ${str(req.params)},
    query: ${str(req.query)},
    body: ${str(req.body)}
  `);
});

const server = http.serve({ port: 3000 });
console.log(`Listening on port ${server.port}...`);

/* Example output
bun main.ts
    [0.90ms] ".env"
    Listening on port 3000...
    8:27:48 PM: 200 GET /
    8:27:52 PM: 405 GET /blog/123
    8:27:56 PM: 200 POST /blog/123
    8:27:58 PM: 200 GET /__endpoints
*/

Endpoints list is available at /__endpoints only in development mode.

Alt text

To install dependencies:

bun install

To run:

bun main.ts

This project was created using bun init in bun v1.0.1. Bun is a fast all-in-one JavaScript runtime.

About

Blazing fast backend, express-like library for Bun. 0 dependencies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published