A simple and fast server framework for bun.js
This repository contains a minimal server framework built on top of Bun for creating efficient and scalable web applications. It provides a structured approach for handling HTTP requests and response capabilities.
bun i jiffyts -g
Jiffy
class:
import Jiffy from './app';
const app = new Jiffy({}); //the {} is important for configs which will be added later
app.get('/api', (req) => {
return 'Hello, world!';
}, 'text/plain');
app.get('/index', (req) => {
return Bun.file('/index.html');
}, 'text/html');
app.listen(3000);
app.get(path: string, handler: RouteHandler, contentType: string = "text/plain")
path
: The URL path for the route.handler
: The route handler function.contentType
: (Optional) The content type of the response. Default is text/plain
.app.post(path: string, handler: RouteHandler, contentType: string = "text/plain")
path
: The URL path for the route.handler
: The route handler function.contentType
: (Optional) The content type of the response. Default is text/plain
.app.put(path: string, handler: RouteHandler, contentType: string = "text/plain")
path
: The URL path for the route.handler
: The route handler function.contentType
: (Optional) The content type of the response. Default is text/plain
.app.delete(path: string, handler: RouteHandler, contentType: string = "text/plain")
path
: The URL path for the route.handler
: The route handler function.contentType
: (Optional) The content type of the response. Default is text/plain
.app.notFound(res: string | BunFile = "Default 404")
res
: (Optional) Custom response for 404 errors. Default is "Default 404".RouteHandler
(req: Request) => string | BunFile
Request
object) and returns either a string or a BunFile
. Use this to define the logic for handling different routes.Contributions are welcome! Please refer to the Gandalf's JavaScript Naming Scheme file for formating.
This project is licensed under the Carbon License v2.2.0. See the LICENSE file for details.
For any queries or feedback, please reach out to [email protected].
Gemini was used to create doucmentation, format the code and help in debuging.
VScode was used as a editor for this project.
This project was created using bun init
in bun v1.0.25. Bun is a fast all-in-one JavaScript runtime.