letchin
v0.0.2
Published
letchin is an http + middleware framwork
Readme
letchin
A minimal HTTP framework built from the ground up using Node’s net module.
letchin provides a simple and lightweight approach to building web servers without relying on Node’s built-in http module.
This is the early foundation of a low-level framework inspired by Express and Koa, but implemented entirely from scratch for educational and experimental development.
Installation
npm install letchinExample Usage
const { tchintchin, mid } = require("letchin");
mid.add("logger", (req, res, next) => {
console.log(`[${req.method}] ${req.path}`);
next();
});
const app = tchintchin();
app.route("GET", "/", mid.logger, (req, res) => {
res.send("Welcome to letchin");
});
app.route("POST", "/data", (req, res) => {
console.log("Body:", req.body);
res.send("Data received");
});
app.listen(3000, () => console.log("Server running on port 3000"));API Overview
tchintchin()
Creates a new application instance.
Methods
| Method | Description |
|---------|--------------|
| app.route(method, path, ...middlewares, handler) | Define a route with optional middlewares and a final handler. |
| app.listen(port, callback) | Start the server on a given port. |
Middleware System
letchin includes a simple middleware manager.
Example
mid.add("auth", (req, res, next) => {
if (req.get("authorization") !== "secret") {
res.statusCode = 401;
res.send("Unauthorized");
} else next();
});
app.route("GET", "/private", mid.auth, (req, res) => {
res.send("Access granted");
});Notes
- Middleware functions receive
(req, res, next). - You can define custom middlewares using
mid.add(name, fn). - Middlewares are executed in order; call
next()to continue.
Request Object (req)
Each route handler and middleware receives a req object representing the HTTP request.
| Property | Type | Description |
|-----------|------|-------------|
| req.method | string | HTTP method (e.g. GET, POST) |
| req.path | string | URL path |
| req.headers | object | Parsed request headers |
| req.body | string | Raw request body |
| req.get(name) | function | Returns a header value by name |
| req.is(type) | function | Checks if Content-Type contains a given string |
Response Object (res)
Each handler also receives a res object used to send responses.
| Method | Description |
|---------|--------------|
| res.send(body) | Sends an HTTP response with status 200 and default headers. |
| res.statusCode | Property used to set custom status codes before sending. |
Example
app.route("GET", "/custom", (req, res) => {
res.statusCode = 201;
res.send("Created");
});Current Limitations
letchin is still under active minimal development.
Current limitations include:
- No query parameter or URL parameter parsing
- No JSON auto-parsing middleware
- No response helpers like
.json()or.set() - Only handles one request per connection (no Keep-Alive yet)
- Error handling is basic and synchronous
Roadmap
- Add
.status()and.set()to response - Add URL parameter parsing
- Add middleware chaining improvements
- Add async body parsing and streaming
- Introduce a testing utility and logging layer
License
Creative Commons Attribution–NonCommercial 4.0 International (CC BY-NC 4.0) © 2025 Oussama Benoujja
You may share and adapt this work for non-commercial purposes, provided that appropriate credit is given. For the full license text, see Creative Commons License.
