We are excited to announce the launch of SVRRouter, a lightweight and efficient routing library designed to integrate seamlessly with SVR.JS 4.x mods. SVRRouter simplifies the process of building web applications by providing a straightforward API for defining routes and middleware, all while maintaining exceptional performance and a minimal footprint.
Key features
- Intuitive routing API - SVRRouter offers a clean and simple interface for defining routes using standard HTTP methods. Developers can easily create routes with methods like
get
,post
,put
,patch
,delete
,head
, andall
. - Middleware support - in addition to routing, SVRRouter allows the integration of middleware functions, enabling developers to handle tasks such as authentication, logging, and request processing efficiently.
- Express middleware compatibility - SVRRouter can incorporate middleware compatible with the
router
library, providing flexibility in integrating existing middleware solutions.
Performance and bundle size
SVRRouter is engineered for performance and minimalism. Below is a comparison of bundle sizes and performance metrics with various routing solutions:
- SVR.JS:
- Bundle Size: 685 bytes
- Performance: 11,210.82 requests per second
- SVR.JS + SVRRouter:
- Bundle Size: 21 KB
- Performance: 10,583.37 requests per second
- SVR.JS + router:
- Bundle Size: 39 KB
- Performance: 9,794.42 requests per second
- SVR.JS + Koa + @koa/router:
- Bundle Size: 446 KB
- Performance: 9,570.57 requests per second
- SVR.JS + Express 4.x:
- Bundle Size: 1.2 MB
- Performance: 6,381.88 requests per second
Performance measured with a "Hello World" application using wrk -c 10 -d 60 -t 3 http://localhost/hello
.
As illustrated, SVRRouter achieves a remarkable balance between bundle size and performance, outperforming larger frameworks like Koa and Express in both metrics.
Getting Started with SVRRouter:
To begin using SVRRouter in your SVR.JS mod, install the svrrouter
npm package either in the SVR.JS installation root or globally:
npm install svrrouter
Here's an example of an SVR.JS mod utilizing SVRRouter:
const svrrouter = require("svrrouter");
const router = svrrouter();
router.get("/hello", (req, res, logFacilities, config, next) => {
res.writeHead(200, "OK", {
"Content-Type": "text/plain"
});
res.write("Hello World!");
res.end();
});
module.exports = router;
module.exports.modInfo = {
name: "Example mod with SVRRouter",
version: "0.0.0"
};
This setup defines a simple route that responds with "Hello World!" when a GET request is made to /hello
.
For comprehensive documentation and advanced usage, please refer to the SVRRouter npm package page.
We believe SVRRouter will significantly enhance your web development experience with SVR.JS by providing a powerful yet lightweight routing solution. We look forward to your feedback and contributions to the project.