Xiara is a framework for building efficient, scalable Node.js server-side applications. It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
Under the hood, Xiara makes use of Express, allowing for easy use of the third-party plugins.
Xiara also features mongodb support out of the box via @xiara/mongo package
I have been continuing adding new features, providing examples and extending the functionalities of the framework, heres a short summary:
So middlewares, what they do? How to use them? First lets look at how to make one.
import { Middleware, IMiddleware, WebServer } from "@xiara/web";
// Define the middleware to be used on all path starting with /private
@Middleware({ path: "/private" })
export class UserMiddleware implements IMiddleware
{
constructor(public my: MyService)
{
}
OnRegister(app: WebServer)
{
// register custom handler or do stuff with the express app
}
// Or use the default middleware handler function
handler(req, res, next)
{
req.user = await Users.findOne({ authToken: req.params.authToken });
next(); // Next is mandatory!
}
}
The constructor as usual can be used for Dependency Injection :)
The decorator @Middleware is used to populate metadata and tell the application how and when to use this middleware. The callback OnRegister can be used to bind methods or further events to the middleware. For example cors, express bodyParser are a great example.
OnRegister(app: WebServer)
{
app.use(cors());
}
The handler is the core function of the middleware, it can be used to populate the request object with additional parameters as shown in the example it adds a user field to the request object that can be later used in the application:
handler(req, res, next)
{
req.user = await Users.findOne({ authToken: req.params.authToken });
next(); // Next is mandatory!
}
All we have left is to add it to our app module.
import { WebModule } from "@xiara/web";
import { UserMiddleware } from "./UserMiddleware";
@WebModule({
middlewares: [
UserMiddleware,
]
})
export class AppModule
{
}
And that would be it, the rest of the magic is all handled by xiara here!
The project is split into multiple repositories as i am trying to create reusable packages and it's also easier to manage updates for me. I've also created an organization to easier keep track of this project.
https://github.com/xiara-io/xiara-web/commit/542ab30f7e2d85826c7c59d08e6fa9f85003c43f
https://github.com/xiara-io/xiara-web/commit/39feb7961671c6c82ab52d5e36514917b5da2b5c
https://github.com/xiara-io/xiara-web/commit/035a396b11f6f034f048a2c34ef2c848b7eeea9c
https://github.com/xiara-io/xiara-mongo/commit/0a29cf8ef1d5c83c7f54b4571738855e28595aa0
https://github.com/xiara-io/xiara-mongo/commit/592ef3af9f9ed989c819e48afa09c855e63865f0
https://github.com/xiara-io/xiara-boilerplate/commit/582fa3047fcabe37786a6986e5f6ba82a9ac89c8
My vision on the project is that theres still a long way to go to implement all the funcitonalities a modern backend framework would require. But even then i am pretty happy with the progress and the framework turns out to be very useful in my projects.
For the next weeks i put the following on the road-map:
If you found any bugs, have suggestions, or just a question please open an issue on github.
https://github.com/xiara-io/xiara-web/issues
Wiki
https://github.com/xiara-io/xiara-core/wiki (for future readers as api reference & documentation)
MIT