We've all been there: you’re building an endpoint, and for the hundredth time, you’re typing out res.status(200).json({ success: true, data: ... }). It feels repetitive, and honestly, it’s a recipe for inconsistency across your API.
I wanted to fix that, so I built BaR-js.
What is it?
BaR (Builder a Response) is a lightweight, framework-agnostic TypeScript library designed to help you serve API responses like a pro—almost like a bartender mixing a drink. It strips away the JSON clutter and ensures every response you send follows a consistent, production-ready schema.
Why use it?
- Consistency: Every endpoint speaks the same language.
-
Fluent API: You can use a chainable syntax like
res.builder.as.ok(data)instead of manually crafting objects every time. -
Traceability: It automatically handles
request_idand timestamps, making debugging so much easier. - Type Safety: Built with strict TypeScript, so you get great IntelliSense support.
It’s this simple:
import express from 'express';
import { BarExpressAdapter } from "@vorlaxen-labs/bar-js";
const app = express();
// 1. Configure the adapter
const bar = new BarExpressAdapter({
environment: 'production',
logger: console,
});
// 2. Register it as middleware
// This injects `res.builder` and `req.bar` into every route!
app.use(bar.handler());
// Now you can use it in any route
app.get('/user', (req, res) => {
return res.builder.as.ok({ name: 'John' }).build();
});
Why "BaR"?
I like the idea that "your code is a work of art, and your responses are its signature." The clearer your response schema, the more professional and valuable your API feels to whoever is consuming it.
The project is still fresh, and I’d love to hear what you think. If you’re looking to clean up your API layer, give it a spin! Feedback, issues, or PRs are more than welcome.
- Check it out on GitHub: https://github.com/vorlaxen-labs/bar-js
- Grab it from NPM: https://www.npmjs.com/package/@vorlaxen-labs/bar-js
Cheers! 🥂
Top comments (0)