Features โ
The product is the C++ HTTP engine plus app.get / middleware / ctx. Everything below that is optional.
Core (this is what you are installing): native workers, radix router, JS handlers, fastGet for static bodies, helmet / cors / JWT helpers, SSE, static files with root in production.
Extras (exist, not the pitch): Express shim, client SDK, decorators, EventBus, file-based routing, Swagger/Postman UI, mock server, GraphQL helper (experimental). Use them if you need them. Do not treat โ60 featuresโ as a reason to trust the parser.
Parser and production constraints: Trust.
โก Core Engine Architecture โ
| Component | Technical Implementation | Benefit |
|---|---|---|
| Event Multiplexer | kqueue (macOS/BSD), epoll (Linux), IOCP (Windows) | Non-blocking event-driven network I/O with $O(1)$ event notifications. |
| Radix Trie Router | Pure C++17 Radix Tree | $O(K)$ parameter and wildcard route lookup regardless of route count. |
| Object Pooling | V8 Monomorphic Shape Pools | Zero Garbage Collection shape churn on Context and Request wrappers. |
| Response Tail Caching | Shared 1-Second Format Buffers | Eliminates redundant string allocations for Date, Server, and Connection. |
| Fast-Path Engine | fastGet, fastPost, fastRoute | Bypasses V8 execution entirely to serve static JSON/text directly from C++ memory. |
| HTTP Parser | RFC 7230 tchar + smuggling guards | Rejects TE+CL, duplicate Content-Length, obs-fold, TRACE; 32 KiB header cap. |
| Socket Tuning | TCP_NODELAY, Linux accept4 | Immediate small-response flush; one-syscall accept on Linux. |
๐ 1. Multi-Version API Router (app.versioning()) โ
Seamlessly handle multiple API versions via headers (e.g. X-API-Version: v2) or path prefixes (/v1, /v2):
app.versioning(
{
v1: appV1,
v2: appV2,
},
{ headerName: "x-api-version" },
);๐ก 2. Type-Safe JSON-RPC 2.0 Engine (app.rpc()) โ
Registers lightweight JSON-RPC endpoints for direct frontend-to-backend procedure execution:
app.rpc("/rpc", {
multiply: ({ a, b }) => a * b,
getUser: ({ id }, ctx) => ({ id, name: "Alice" }),
});๐ 3. Terminal CLI Route Printer (app.printRoutes()) โ
Prints a clean, formatted ASCII route table to the terminal showing all registered methods and endpoints:
app.printRoutes();โณ 4. Automated Periodic SSE Ticker (ctx.sseInterval()) โ
Streams periodic real-time Server-Sent Events at configured time intervals:
app.get("/live-prices", (ctx) => {
return ctx.sseInterval(() => ({ price: Math.random() * 100 }), 1000);
});๐ 5. Granular Dynamic Rate Limiter (rateLimitByKey()) โ
Restricts request rate dynamically based on custom keys (e.g. User ID, API Key, Tenant ID):
import { rateLimitByKey } from "velociradix";
app.use(
rateLimitByKey({
max: 100,
windowMs: 60000,
keyFn: (ctx) => ctx.get("x-api-key") || ctx.ip,
}),
);๐ 6. File-System Based Auto Routing (app.autoRoute()) โ
Automatically scans routes directories recursively and maps exported route functions (GET, POST, PUT, DELETE, etc.) or default handlers to HTTP paths:
// Scans ./routes directory recursively
app.autoRoute("./routes");๐ 7. WebSockets โ
app.ws() was removed in 8.2.0. It never performed a 101 Switching Protocols upgrade or framed WebSocket messages. Use a dedicated WebSocket library (with Origin checks) if you need a real WebSocket.
๐ฎ 8. Experimental GraphQL helper (app.graphql()) โ
POST-only toy resolver (8 KiB query cap). Not a GraphQL server โ no depth/cost limits.
app.graphql("/graphql", `type Query { user(id: ID!): User }`, {
user: (ctx) => ({ id: ctx.params.id || 1, name: "Alice", role: "admin" }),
});๐ก 9. Multi-Channel SSE Broadcast (app.sseBroadcast()) โ
Stream named events to connected clients across specific broadcast channels:
// Broadcast to all clients subscribed to 'live-feed'
app.sseBroadcast("live-feed", { timestamp: Date.now(), activeUsers: 142 });๐ก๏ธ 10. Circuit Breaker Resiliency Middleware (circuitBreaker()) โ
Protects external database or microservice endpoints with failure threshold monitoring and state transition (Closed, Open, Half-Open):
import { circuitBreaker } from "velociradix";
app.use(circuitBreaker({ failureThreshold: 5, resetTimeoutMs: 10000 }));๐ญ 11. Built-in API Mocking Engine (app.mockServer()) โ
Registers mock endpoints with simulated latency delay for frontend integration:
app.mockServer({
"GET /api/users": {
status: 200,
delayMs: 100,
body: [{ id: 1, name: "Alice" }],
},
"POST /api/orders": { status: 201, delayMs: 200, body: { orderId: 99 } },
});โฑ๏ธ 12. Fluent HTTP Cache-Control Helper (ctx.cacheControl()) โ
Expressive helper for max-age, s-maxage, stale-while-revalidate, public, private, and immutable headers:
app.get("/assets/logo.png", (ctx) => {
ctx.cacheControl({ maxAge: 3600, public: true, staleWhileRevalidate: 86400 });
return ctx.sendFile("./public/logo.png");
});โก 13. Programmatic Load Tester & Benchmark Runner (app.bench()) โ
Runs local throughput (RPS) and latency benchmarking:
const stats = await app.bench({ iterations: 1000, path: "/api/users" });
console.log(`RPS: ${stats.rps} req/sec | Total Time: ${stats.totalMs} ms`);๐ง 14. Dynamic Auto-Scaling Worker Threads (app.autoScale()) โ
Dynamically adjusts native C++ worker thread pool allocation based on system heap memory and load:
app.autoScale({ minWorkers: 2, maxWorkers: 8, intervalMs: 5000 });